
%This code calculates the equilibrium in a model with no multinational
%activity

%Please refer to the "solve_equilibrium_baseline" code for details on what
%each component means

clear
tic

target_mig=0.9;
mig_cost_change=1.05;

mig_cost_change1=1;
mig_cost_change2=1;
mig_cost_change3=1;
mig_cost_change4=1;

%Parameters

correlation=0;
lambda=13.25;
epsilon=1.7;
iota=3.75;
theta=4;
kappa=6.17;
nu=0;
nu2=0;

%Migration comparative advantage
A_us_IT=1;
A_us_Oth=1;
A_us_Man=1;
A_us_Fin=1;
A_in_IT=1;
A_in_Oth=1;
A_in_Man=1;
A_in_Fin=1;
A_eu_IT=1;
A_eu_Oth=1;
A_eu_Man=1;
A_eu_Fin=1;
A_ca_IT=1;
A_ca_Oth=1;
A_ca_Man=1;
A_ca_Fin=1;
A_ch_IT=1;
A_ch_Oth=1;
A_ch_Man=1;
A_ch_Fin=1;
A_ot_IT=1;
A_ot_Oth=1;
A_ot_Man=1;
A_ot_Fin=1;

%Trade costs
tau_us_in_Oth=1;
tau_us_eu_Oth=1;
tau_us_ca_Oth=1;
tau_us_ch_Oth=1;
tau_us_ot_Oth=1;

tau_us_in_IT=1;
tau_us_eu_IT=1;
tau_us_ca_IT=1;
tau_us_ch_IT=1;
tau_us_ot_IT=1;

tau_us_in_Man=1;
tau_us_eu_Man=1;
tau_us_ca_Man=1;
tau_us_ch_Man=1;
tau_us_ot_Man=1;

tau_us_in_Fin=1;
tau_us_eu_Fin=1;
tau_us_ca_Fin=1;
tau_us_ch_Fin=1;
tau_us_ot_Fin=1;


tau_in_us_Oth=1;
tau_in_eu_Oth=1;
tau_in_ca_Oth=1;
tau_in_ch_Oth=1;
tau_in_ot_Oth=1;

tau_in_us_IT=1;
tau_in_eu_IT=1;
tau_in_ca_IT=1;
tau_in_ch_IT=1;
tau_in_ot_IT=1;

tau_in_us_Man=1;
tau_in_eu_Man=1;
tau_in_ca_Man=1;
tau_in_ch_Man=1;
tau_in_ot_Man=1;

tau_in_us_Fin=1;
tau_in_eu_Fin=1;
tau_in_ca_Fin=1;
tau_in_ch_Fin=1;
tau_in_ot_Fin=1;


tau_eu_us_Oth=1;
tau_eu_in_Oth=1;
tau_eu_ca_Oth=1;
tau_eu_ch_Oth=1;
tau_eu_ot_Oth=1;

tau_eu_us_IT=1;
tau_eu_in_IT=1;
tau_eu_ca_IT=1;
tau_eu_ch_IT=1;
tau_eu_ot_IT=1;

tau_eu_us_Fin=1;
tau_eu_in_Fin=1;
tau_eu_ca_Fin=1;
tau_eu_ch_Fin=1;
tau_eu_ot_Fin=1;

tau_eu_us_Man=1;
tau_eu_in_Man=1;
tau_eu_ca_Man=1;
tau_eu_ch_Man=1;
tau_eu_ot_Man=1;

tau_ca_us_Oth=1;
tau_ca_in_Oth=1;
tau_ca_eu_Oth=1;
tau_ca_ch_Oth=1;
tau_ca_ot_Oth=1;

tau_ca_us_IT=1;
tau_ca_in_IT=1;
tau_ca_eu_IT=1;
tau_ca_ch_IT=1;
tau_ca_ot_IT=1;

tau_ca_us_Man=1;
tau_ca_in_Man=1;
tau_ca_eu_Man=1;
tau_ca_ch_Man=1;
tau_ca_ot_Man=1;

tau_ca_us_Fin=1;
tau_ca_in_Fin=1;
tau_ca_eu_Fin=1;
tau_ca_ch_Fin=1;
tau_ca_ot_Fin=1;

tau_ch_us_Oth=1;
tau_ch_in_Oth=1;
tau_ch_eu_Oth=1;
tau_ch_ca_Oth=1;
tau_ch_ot_Oth=1;

tau_ch_us_IT=1;
tau_ch_in_IT=1;
tau_ch_eu_IT=1;
tau_ch_ca_IT=1;
tau_ch_ot_IT=1;

tau_ch_us_Man=1;
tau_ch_in_Man=1;
tau_ch_eu_Man=1;
tau_ch_ca_Man=1;
tau_ch_ot_Man=1;

tau_ch_us_Fin=1;
tau_ch_in_Fin=1;
tau_ch_eu_Fin=1;
tau_ch_ca_Fin=1;
tau_ch_ot_Fin=1;

tau_ot_us_Oth=1;
tau_ot_in_Oth=1;
tau_ot_eu_Oth=1;
tau_ot_ch_Oth=1;
tau_ot_ca_Oth=1;

tau_ot_us_IT=1;
tau_ot_in_IT=1;
tau_ot_eu_IT=1;
tau_ot_ch_IT=1;
tau_ot_ca_IT=1;

tau_ot_us_Man=1;
tau_ot_in_Man=1;
tau_ot_eu_Man=1;
tau_ot_ch_Man=1;
tau_ot_ca_Man=1;

tau_ot_us_Fin=1;
tau_ot_in_Fin=1;
tau_ot_eu_Fin=1;
tau_ot_ch_Fin=1;
tau_ot_ca_Fin=1;

%MNE costs

deltab_us_in_IT=1;
deltab_us_eu_IT=1;
deltab_us_ca_IT=1;
deltab_us_ch_IT=1;

deltab_us_in_Man=1;
deltab_us_eu_Man=1;
deltab_us_ca_Man=1;
deltab_us_ch_Man=1;

deltab_us_in_Fin=1;
deltab_us_eu_Fin=1;
deltab_us_ca_Fin=1;
deltab_us_ch_Fin=1;

deltab_in_us_IT=1;
deltab_in_eu_IT=1;
deltab_in_ca_IT=1;
deltab_in_ch_IT=1;

deltab_in_us_Man=1;
deltab_in_eu_Man=1;
deltab_in_ca_Man=1;
deltab_in_ch_Man=1;

deltab_in_us_Fin=1;
deltab_in_eu_Fin=1;
deltab_in_ca_Fin=1;
deltab_in_ch_Fin=1;

deltab_eu_us_IT=1;
deltab_eu_in_IT=1;
deltab_eu_ca_IT=1;
deltab_eu_ch_IT=1;

deltab_eu_us_Man=1;
deltab_eu_in_Man=1;
deltab_eu_ca_Man=1;
deltab_eu_ch_Man=1;

deltab_eu_us_Fin=1;
deltab_eu_in_Fin=1;
deltab_eu_ca_Fin=1;
deltab_eu_ch_Fin=1;

deltab_ca_us_IT=1;
deltab_ca_in_IT=1;
deltab_ca_eu_IT=1;
deltab_ca_ch_IT=1;

deltab_ca_us_Man=1;
deltab_ca_in_Man=1;
deltab_ca_eu_Man=1;
deltab_ca_ch_Man=1;

deltab_ca_us_Fin=1;
deltab_ca_in_Fin=1;
deltab_ca_eu_Fin=1;
deltab_ca_ch_Fin=1;

deltab_ch_us_IT=1;
deltab_ch_in_IT=1;
deltab_ch_eu_IT=1;
deltab_ch_ca_IT=1;

deltab_ch_us_Man=1;
deltab_ch_in_Man=1;
deltab_ch_eu_Man=1;
deltab_ch_ca_Man=1;

deltab_ch_us_Fin=1;
deltab_ch_in_Fin=1;
deltab_ch_eu_Fin=1;
deltab_ch_ca_Fin=1;


%Technology
T_us_IT=1;
T_us_Oth=1;
T_us_Man=1;
T_us_Fin=1;

T_in_IT=1;
T_in_Oth=1;
T_in_Man=1;
T_in_Fin=1;

T_eu_IT=1;
T_eu_Oth=1;
T_eu_Man=1;
T_eu_Fin=1;

T_ca_IT=1;
T_ca_Oth=1;
T_ca_Man=1;
T_ca_Fin=1;

T_ch_IT=1;
T_ch_Oth=1;
T_ch_Man=1;
T_ch_Fin=1;

T_ot_IT=1;
T_ot_Oth=1;
T_ot_Man=1;
T_ot_Fin=1;

%Total labor supply
N_in=1;
N_us=1;
N_eu=1;
N_ca=1;
N_ch=1;
N_ot=1;

L_us=1;
L_in=1;
L_eu=1;
L_ca=1;
L_ch=1;
L_ot=1;



%High skill share parameters
psi_d=1;
psi_s=1;
psi_f=1;

psi_l=1;
psi_h=1;
 

%Data needed

%Order: US India Europe Canada China Other


%Trade shares
Trade_shares_IT_us=[0.9719	0.0015	0.0119	0.0027	0.0017	0.0103]/sum([0.9719	0.0015	0.0119	0.0027	0.0017	0.0103]);
Trade_shares_IT_in=[0.0382	0.8340	0.0322	0.0005	0.0030	0.0921]/sum([0.0382	0.8340	0.0322	0.0005	0.0030	0.0921]);
Trade_shares_IT_eu=[0.0246	0.0021	0.9370	0.0010	0.0087	0.0266]/sum([0.0246	0.0021	0.9370	0.0010	0.0087	0.0266]);
Trade_shares_IT_ca=[0.0434	0.00003	0.0082	0.9298	0.0005	0.0181]/sum([0.0434	0.00003	0.0082	0.9298	0.0005	0.0181]);
Trade_shares_IT_ch=[0.0059	0.0004	0.0198	0.0002	0.9511	0.0225]/sum([0.0059	0.0004	0.0198	0.0002	0.9511	0.0225]);
Trade_shares_IT_ot=[0.0244	0.0182	0.0489	0.0031	0.0127	0.8927]/sum([0.0244	0.0182	0.0489	0.0031	0.0127	0.8927]);

Trade_shares_Oth_us=[0.9404	0.0010	0.0087	0.0113	0.0068	0.0319]/sum([0.9404	0.0010	0.0087	0.0113	0.0068	0.0319]);
Trade_shares_Oth_in=[0.0028	0.9079	0.0074	0.0004	0.0052	0.0763]/sum([0.0028	0.9079	0.0074	0.0004	0.0052	0.0763]);
Trade_shares_Oth_eu=[0.0074	0.0011	0.9318	0.0016	0.0053	0.0527]/sum([0.0074	0.0011	0.9318	0.0016	0.0053	0.0527]);
Trade_shares_Oth_ca=[0.0510	0.0008	0.0151	0.8864	0.0113	0.0354]/sum([0.0510	0.0008	0.0151	0.8864	0.0113	0.0354]);
Trade_shares_Oth_ch=[0.0029	0.0011	0.0047	0.0011	0.9440	0.0462]/sum([0.0029	0.0011	0.0047	0.0011	0.9440	0.0462]);
Trade_shares_Oth_ot=[0.0123	0.0032	0.0274	0.0022	0.0186	0.9363]/sum([0.0123	0.0032	0.0274	0.0022	0.0186	0.9363]);

Trade_shares_Man_us=[0.6716	0.0029	0.0729	0.0322	0.0714	0.1491]/sum([0.6716	0.0029	0.0729	0.0322	0.0714	0.1491]);
Trade_shares_Man_in=[0.0151	0.7545	0.0572	0.0034	0.0623	0.1074]/sum([0.0151	0.7545	0.0572	0.0034	0.0623	0.1074]);
Trade_shares_Man_eu=[0.0370	0.0039	0.7552	0.0033	0.0565	0.1441]/sum([0.0370	0.0039	0.7552	0.0033	0.0565	0.1441]);
Trade_shares_Man_ca=[0.4357	0.0017	0.0997	0.2416	0.0791	0.1421]/sum([0.4357	0.0017	0.0997	0.2416	0.0791	0.1421]);
Trade_shares_Man_ch=[0.0090	0.0006	0.0260	0.0005	0.8641	0.0998]/sum([0.0090	0.0006	0.0260	0.0005	0.8641	0.0998]);
Trade_shares_Man_ot=[0.0436	0.0054	0.1142	0.0029	0.0984	0.7355]/sum([0.0436	0.0054	0.1142	0.0029	0.0984	0.7355]);


Trade_shares_Fin_us=[0.9688	0.00000040	0.0157	0.0011	0.000008	0.0144]/sum([0.9688	0.00000040	0.0157	0.0011	0.000008	0.0144]);
Trade_shares_Fin_in=[0.0001	0.9915	0.0008	0.000004	0.000036	0.0074]/sum([0.0001	0.9915	0.0008	0.000004	0.000036	0.0074]);
Trade_shares_Fin_eu=[0.0152	0.0000004	0.9638	0.0006	0.0001	0.0203]/sum([0.0152	0.0000004	0.9638	0.0006	0.0001	0.0203]);
Trade_shares_Fin_ca=[0.0246	0.000003	0.0189	0.9451	0.0001	0.0113]/sum([0.0246	0.000003	0.0189	0.9451	0.0001	0.0113]);
Trade_shares_Fin_ch=[0.0003	0.000001	0.0020	0.00002	0.9867	0.0109]/sum([0.0003	0.000001	0.0020	0.00002	0.9867	0.0109]);
Trade_shares_Fin_ot=[0.0325	0.0006	0.0795	0.0024	0.0034	0.8816]/sum([0.0325	0.0006	0.0795	0.0024	0.0034	0.8816]);



%MNE shares - setting MNE shares to 0

MNE_shares_IT_us=[1 0 0 0 0];
MNE_shares_IT_in=[0 1 0 0 0];
MNE_shares_IT_eu=[0 0 1 0 0];
MNE_shares_IT_ca=[0 0 0 1 0];
MNE_shares_IT_ch=[0 0 0 0 1];

MNE_shares_Man_us=[1 0 0 0 0];
MNE_shares_Man_in=[0 1 0 0 0];
MNE_shares_Man_eu=[0 0 1 0 0];
MNE_shares_Man_ca=[0 0 0 1 0];
MNE_shares_Man_ch=[0 0 0 0 1];


MNE_shares_Fin_us=[1 0 0 0 0];
MNE_shares_Fin_in=[0 1 0 0 0];
MNE_shares_Fin_eu=[0 0 1 0 0];
MNE_shares_Fin_ca=[0 0 0 1 0];
MNE_shares_Fin_ch=[0 0 0 0 1];



%Production Shares

Prod_shares_IT_us=[0.9462	0.0008	0.0220	0.0034	0.0019	0.0257]/sum([0.9462	0.0008	0.0220	0.0034	0.0019	0.0257]);
Prod_shares_IT_in=[0.0350	0.4498	0.0462	0.0001	0.0029	0.4661]/sum([0.0350	0.4498	0.0462	0.0001	0.0029	0.4661]);
Prod_shares_IT_eu=[0.0127	0.0008	0.9222	0.0007	0.0069	0.0567]/sum([0.0127	0.0008	0.9222	0.0007	0.0069	0.0567]);
Prod_shares_IT_ca=[0.0335	0.0001	0.0111	0.9140	0.0009	0.0404]/sum([0.0335	0.0001	0.0111	0.9140	0.0009	0.0404]);
Prod_shares_IT_ch=[0.0052	0.0002	0.0241	0.0001	0.9289	0.0414]/sum([0.0052	0.0002	0.0241	0.0001	0.9289	0.0414]);
Prod_shares_IT_ot=[0.0102	0.0021	0.0242	0.0014	0.0072	0.9550]/sum([0.0102	0.0021	0.0242	0.0014	0.0072	0.9550]);


Prod_shares_Oth_us=[0.9552	0.0004	0.0084	0.0064	0.0026	0.0262]/sum([0.9552	0.0004	0.0084	0.0064	0.0026	0.0262]);
Prod_shares_Oth_in=[0.0066	0.9313	0.0086	0.0007	0.0069	0.0459]/sum([0.0066	0.9313	0.0086	0.0007	0.0069	0.0459]);
Prod_shares_Oth_eu=[0.0079	0.0010	0.9314	0.0017	0.0038	0.0522]/sum([0.0079	0.0010	0.9314	0.0017	0.0038	0.0522]);
Prod_shares_Oth_ca=[0.0883	0.0004	0.0140	0.8523	0.0079	0.0370]/sum([0.0883	0.0004	0.0140	0.8523	0.0079	0.0370]);
Prod_shares_Oth_ch=[0.0076	0.0009	0.0065	0.0016	0.9380	0.0438]/sum([0.0076	0.0009	0.0065	0.0016	0.9380	0.0438]);
Prod_shares_Oth_ot=[0.0150	0.0054	0.0275	0.0020	0.0194	0.9305]/sum([0.0150	0.0054	0.0275	0.0020	0.0194	0.9305]);

Prod_shares_Man_us=[0.7516	0.0027	0.0435	0.0523	0.0211	0.1288]/sum([0.7516	0.0027	0.0435	0.0523	0.0211	0.1288]);
Prod_shares_Man_in=[0.0206	0.8396	0.0291	0.0013	0.0084	0.1009]/sum([0.0206	0.8396	0.0291	0.0013	0.0084	0.1009]);
Prod_shares_Man_eu=[0.0587	0.0073	0.6386	0.0086	0.0437	0.2431]/sum([0.0587	0.0073	0.6386	0.0086	0.0437	0.2431]);
Prod_shares_Man_ca=[0.4544	0.0076	0.0483	0.3662	0.0137	0.1098]/sum([0.4544	0.0076	0.0483	0.3662	0.0137	0.1098]);
Prod_shares_Man_ch=[0.0323	0.0044	0.0268	0.0038	0.8149	0.1177]/sum([0.0323	0.0044	0.0268	0.0038	0.8149	0.1177]);
Prod_shares_Man_ot=[0.0600	0.0068	0.0609	0.0061	0.0837	0.7824]/sum([0.0600	0.0068	0.0609	0.0061	0.0837	0.7824]);

Prod_shares_Fin_us=[0.9456	0.0024	0.0001	0.00001	0.0125	0.0394]/sum([0.9456	0.0024	0.0001	0.00001	0.0125	0.0394]);
Prod_shares_Fin_in=[0.00001	0.9891	0.00001	0.000004	0.00001	0.0109]/sum([0.00001	0.9891	0.00001	0.000004	0.00001	0.0109]);
Prod_shares_Fin_eu=[0.0169	0.0001	0.8743	0.0020	0.0008	0.1060]/sum([0.0169	0.0001	0.8743	0.0020	0.0008	0.1060]);
Prod_shares_Fin_ca=[0.0107	0.000002	0.0053	0.9530	0.0001	0.0309]/sum([0.0107	0.000002	0.0053	0.9530	0.0001	0.0309]);
Prod_shares_Fin_ch=[0.00002	0.00001	0.0002	0.00002	0.9883	0.0114]/sum([0.00002	0.00001	0.0002	0.00002	0.9883	0.0114]);
Prod_shares_Fin_ot=[0.0127	0.0004	0.0152	0.0010	0.0036	0.9671]/sum([0.0127	0.0004	0.0152	0.0010	0.0036	0.9671]);

%High-Skill Labor shares: skill_shares_x_x, share of high-skill wagebill
%spent on type of high-skill labor by companies in x from source country x

%Order domestic (us-us, eu-eu, ca-ca): Domestic-IT Foreign-IT Domestic-Man
%Foreign-Man Domestic-Oth Foreign-Oth Domestic-Fin Foreign-Fin

skill_shares_us_us=[0.896198365	0.103801635	0.850243804	0.149756196	0.90966979	0.09033021	0.944602042	0.055397958];
skill_shares_eu_eu=[0.908662442	0.091337558	0.89706554	0.10293446	0.875192929	0.124807071	0.93347518	0.06652482];
skill_shares_ca_ca=[0.642440287	0.357559713	0.548903938	0.451096062	0.875192929	0.124807071	0.587721123	0.412278877];


%Low skill labor shares by industry

%Adding over MNE shares from baseline code

low_skill_share_us=[ sum([6.58E-02	1.83E-04	2.80E-03	1.23E-04	2.26E-06])	sum([4.75E-02	3.71E-05	1.43E-02	8.12E-04	9.93E-05])	8.19E-01	sum([4.20E-02	1.78E-05	6.22E-03	1.24E-03	3.78E-05])]/sum([6.58E-02	1.83E-04	2.80E-03	1.23E-04	2.26E-06	4.75E-02	3.71E-05	1.43E-02	8.12E-04	9.93E-05	8.19E-01	4.20E-02	1.78E-05	6.22E-03	1.24E-03	3.78E-05]); 
low_skill_share_in=[sum([0.000740073	0.005411053	0.000668812	3.19217E-05	4.10906E-05])	sum([0.000483251	0.009935595	0.000806531	5.30287E-06	4.96768E-05])	0.978149629	sum([0.000172908	0.002822297	0.000629015	1.04559E-05	4.23878E-05])]/sum([0.000740073	0.005411053	0.000668812	3.19217E-05	4.10906E-05	0.000483251	0.009935595	0.000806531	5.30287E-06	4.96768E-05	0.978149629	0.000172908	0.002822297	0.000629015	1.04559E-05	4.23878E-05]);
low_skill_share_eu=[sum([0.004323896	0.000113337	0.051677893	0.000219632	0.000140664])	sum([0.021871769	0.001115899	0.082233804	0.000532217	0.002102825])	0.800036799	sum([0.004061478	0.00030208	0.029992227	0.000326968	0.000948512])]/sum([0.004323896	0.000113337	0.051677893	0.000219632	0.000140664	0.021871769	0.001115899	0.082233804	0.000532217	0.002102825	0.800036799	0.004061478	0.00030208	0.029992227	0.000326968	0.000948512]); 
low_skill_share_ca=[sum([0.006637912	9.44043E-07	0.000166812	0.058058462	0.000214123])	sum([0.077976202	7.59338E-06	0.000543477	0.029437062	0.000201376])	0.781943278	sum([0.006856877	1.42931E-06	6.45572E-05	0.037889656	2.38218E-07])]/sum([0.006637912	9.44043E-07	0.000166812	0.058058462	0.000214123	0.077976202	7.59338E-06	0.000543477	0.029437062	0.000201376	0.781943278	0.006856877	1.42931E-06	6.45572E-05	0.037889656	2.38218E-07]);
low_skill_share_ch=[sum([0.000195808	2.31542E-06	0.00019757	3.32671E-06	0.015817407])	sum([0.00365296	3.23312E-05	0.003414303	0.000117111	0.169793708])	0.799474388	sum([6.23737E-05	1.62372E-06	0.00011303	1.03422E-08	0.007121734])]/sum([0.000195808	2.31542E-06	0.00019757	3.32671E-06	0.015817407	0.00365296	3.23312E-05	0.003414303	0.000117111	0.169793708	0.799474388	6.23737E-05	1.62372E-06	0.00011303	1.03422E-08	0.007121734]);
low_skill_share_ot=[0.022915888	0.091957062	0.874757475	0.010369574]/sum([0.022915888	0.091957062	0.874757475	0.010369574]);



%Shares over total labor: total_shares_x_y, share of labor
%type-industry in country x by companies from y


% Order US, Europe, Canada own source: Native-IT Foreign-IT LowSkilled-IT
% Native-Man Foreign-Man LowSkilled-Man Native-Oth Foreign-Oth
% LowSkilled-Fin Native-Man Foreign-Fin LowSkilled-Fin

% Order US, Europe, Canada other source: Native-IT Source-IT Foreign-IT LowSkilled-IT Native-Man
% Source-Man Foreign-Man LowSkilled-Man Native-Fin Source-Fin Foreign-Fin LowSkilled-Fin

%Order India - China: Own source: HighSkilled-IT HighSkilled-Man
%HighSkilled-Oth LowSkilled-IT LowSkilled-Man LowSkilled-Oth
%HighSkilled-Fin LowSkilled-Fin

% Order Other: HighSkilled-IT HighSkilled-Man HighSkilled-Oth LowSkilled-IT
% LowSkilled-Man LowSkilled-Oth HighSkilled-Fin LowSkilled-Fin


%US
tot_us=sum([8.62E-02	9.99E-03	3.18E-02	2.41E-02	4.24E-03	2.30E-02	2.97E-01	2.95E-02	3.96E-01	4.19E-02	2.46E-03	2.03E-02])+sum([1.76E-05	2.29E-04	2.05E-05	8.84E-05	5.56E-06	1.46E-05	1.97E-06	1.79E-05	4.22E-06	1.46E-05	1.46E-09	8.60E-06])+...
sum([2.47E-03	6.47E-05	1.56E-03	1.35E-03	7.16E-03	9.46E-05	1.28E-03	6.92E-03	4.55E-03	2.83E-04	1.74E-03	3.01E-03])+sum([1.60E-04	1.19E-06	1.87E-05	5.96E-05	4.06E-04	2.03E-05	5.79E-05	3.92E-04	1.18E-03	2.30E-05	1.06E-04	5.98E-04])+...
sum([2.74E-06	1.37E-07	4.25E-07	1.09E-06	1.31E-06	6.24E-06	5.16E-05	4.80E-05	2.44E-06	1.25E-05	2.50E-05	1.83E-05]);

%First, create a matrix that has High-skill and Low-skill shares for each
%industry, starting with IT, Man, Oth, and Fin.
total_shares_us_us_temp=[sum([8.62E-02	9.99E-03])	3.18E-02...
    sum([2.41E-02	4.24E-03])	2.30E-02...
    sum([2.97E-01	2.95E-02])	3.96E-01...
    sum([4.19E-02	2.46E-03])	2.03E-02]/tot_us;

%Add shares of high and low skill belonging to foreign MNEs (assign 0s to
%Other industry which had no MNEs
total_shares_us_mne=total_shares_us_us_temp+[sum([1.76E-05	2.29E-04	2.05E-05])	8.84E-05	sum([5.56E-06	1.46E-05	1.97E-06])	1.79E-05	0 0 sum([4.22E-06	1.46E-05	1.46E-09])	8.60E-06]/tot_us+...
[sum([2.47E-03	6.47E-05	1.56E-03])	1.35E-03	sum([7.16E-03	9.46E-05	1.28E-03])	6.92E-03	0 0 sum([4.55E-03	2.83E-04	1.74E-03])	3.01E-03]/tot_us+...
[sum([1.60E-04	1.19E-06	1.87E-05])	5.96E-05	sum([4.06E-04	2.03E-05	5.79E-05])	3.92E-04	0 0 sum([1.18E-03	2.30E-05	1.06E-04])	5.98E-04]/tot_us+...
[sum([2.74E-06	1.37E-07	4.25E-07])	1.09E-06	sum([1.31E-06	6.24E-06	5.16E-05])	4.80E-05	0 0 sum([2.44E-06	1.25E-05	2.50E-05])	1.83E-05]/tot_us;

%Re-adjust shares to assign them the immigrant-native intensity of US firms
%in each sector. This is done by interacting the high-skill share by the
%immigrant-native intensity of US firms. The low skill share stays the
%same.

%Order: IT- High skill Natives, IT High-skill Imm, IT Low skill, Man- High
%skill Natives, Man High-skill Imm, Man Low skill, Oth- High skill Natives, Oth
%High-skill Imm, Oth Low skill, Fin- High skill Natives, Fin High-skill Imm, Fin Low skill,

total_shares_us_us=[skill_shares_us_us(1,1)*total_shares_us_mne(1,1) skill_shares_us_us(1,2)*total_shares_us_mne(1,1) total_shares_us_mne(1,2)...
    skill_shares_us_us(1,3)*total_shares_us_mne(1,3) skill_shares_us_us(1,4)*total_shares_us_mne(1,3) total_shares_us_mne(1,4)...
    skill_shares_us_us(1,5)*total_shares_us_mne(1,5) skill_shares_us_us(1,6)*total_shares_us_mne(1,5) total_shares_us_mne(1,6)...
    skill_shares_us_us(1,7)*total_shares_us_mne(1,7) skill_shares_us_us(1,8)*total_shares_us_mne(1,7) total_shares_us_mne(1,8)];



%India

tot_in=sum([0.012332141	0.007212015	0.227158481	0.003987341	0.007321422	0.720786827	0.00925331	0.002079717]);

total_shares_in_in=[0.012332141	0.007212015	0.227158481	0.003987341	0.007321422	0.720786827	0.00925331	0.002079717]/tot_in;


%Europe - adjust shares same as in the US

tot_eu=sum([0.039973798	0.004018114	0.031235996	0.032881808	0.003773048	0.049705099	0.230349003	0.032848968	0.483571314	0.028454776	0.002027851	0.018128392])+sum([8.76684E-05	3.86027E-07	8.42629E-06	6.85052E-05	0.000446201	2.93084E-06	4.82688E-05	0.00067449	0.000286594	4.99492E-07	1.99249E-05	0.000182588])+...
    sum([0.003344613	2.99029E-05	0.000306293	0.00261352	0.008745592	8.08532E-05	0.000922666	0.013220092	0.00385328	5.05437E-05	0.000224063	0.002454905])+sum([0.000169889	9.79278E-07	1.60978E-05	0.000132754	0.000212811	2.96675E-06	2.14524E-05	0.000321691	0.000310208	1.52953E-06	2.05776E-05	0.000197632])+...
    sum([0.000108806	2.48206E-06	8.45495E-06	8.50221E-05	0.000840831	1.92193E-06	9.45598E-05	0.001271024	0.00089989	8.32617E-06	5.58052E-05	0.000573315]);

total_shares_eu_eu_temp=[sum([0.039973798	0.004018114])	0.031235996	sum([0.032881808	0.003773048])	0.049705099	sum([0.230349003	0.032848968])	0.483571314	sum([0.028454776	0.002027851])	0.018128392]/tot_eu;
total_shares_eu_in=[sum([8.76684E-05	3.86027E-07	8.42629E-06])	6.85052E-05	sum([0.000446201	2.93084E-06	4.82688E-05])	0.00067449	0 0 sum([0.000286594	4.99492E-07	1.99249E-05])	0.000182588]/tot_eu;
total_shares_eu_us=[sum([0.003344613	2.99029E-05	0.000306293])	0.00261352	sum([0.008745592	8.08532E-05	0.000922666])	0.013220092	0 0 sum([0.00385328	5.05437E-05	0.000224063])	0.002454905]/tot_eu;
total_shares_eu_ca=[sum([0.000169889	9.79278E-07	1.60978E-05])	0.000132754	sum([0.000212811	2.96675E-06	2.14524E-05])	0.000321691	0 0 sum([0.000310208	1.52953E-06	2.05776E-05])	0.000197632]/tot_eu;
total_shares_eu_ch=[sum([0.000108806	2.48206E-06	8.45495E-06])	8.50221E-05	sum([0.000840831	1.92193E-06	9.45598E-05])	0.001271024	0 0 sum([0.00089989	8.32617E-06	5.58052E-05])	0.000573315]/tot_eu;


total_shares_eu_mne=total_shares_eu_eu_temp+total_shares_eu_in+total_shares_eu_us+total_shares_eu_ca+total_shares_eu_ch;

total_shares_eu_eu=[skill_shares_eu_eu(1,1)*total_shares_eu_mne(1,1) skill_shares_eu_eu(1,2)*total_shares_eu_mne(1,1) total_shares_eu_mne(1,2)...
    skill_shares_eu_eu(1,3)*total_shares_eu_mne(1,3) skill_shares_eu_eu(1,4)*total_shares_eu_mne(1,3) total_shares_eu_mne(1,4)...
    skill_shares_eu_eu(1,5)*total_shares_eu_mne(1,5) skill_shares_eu_eu(1,6)*total_shares_eu_mne(1,5) total_shares_eu_mne(1,6)...
    skill_shares_eu_eu(1,7)*total_shares_eu_mne(1,7) skill_shares_eu_eu(1,8)*total_shares_eu_mne(1,7) total_shares_eu_mne(1,8)];



%Canada - adjust shares same as in the US


tot_ca=sum([0.039436734	0.021949102	0.033205667	0.003662321	0.003009741	0.016836086	0.219397743	0.100220348	0.447220727	0.007514817	0.005271548	0.02167042])+sum([6.4125E-07	3.86671E-08	3.1823E-07	5.39931E-07	9.44707E-07	1.40268E-07	6.36104E-07	4.34292E-06	2.83481E-07	1.48871E-08	1.83971E-07	8.17472E-07])+...
    sum([0.000113308	1.39886E-05	4.90749E-05	9.54054E-05	6.7615E-05	8.69784E-06	4.6869E-05	0.000310833	1.28039E-05	2.79343E-06	6.18835E-06	3.69225E-05])+sum([0.004508862	0.000290908	0.002218566	0.003796454	0.009701168	0.0007585	0.00721404	0.044597319	0.001359954	9.6613E-05	0.000857377	0.003921688])+...
    sum([0.000145445	5.05184E-05	3.04312E-05	0.000122465	2.50536E-05	1.81618E-06	1.87732E-05	0.000115174	4.72469E-08	1.51113E-08	1.80317E-08	1.36245E-07]);

total_shares_ca_ca_temp=[sum([0.039436734	0.021949102])	0.033205667	sum([0.003662321	0.003009741])	0.016836086	sum([0.219397743	0.100220348])	0.447220727	sum([0.007514817	0.005271548])	0.02167042]/tot_ca;
total_shares_ca_in=[sum([6.4125E-07	3.86671E-08	3.1823E-07])	5.39931E-07	sum([9.44707E-07	1.40268E-07	6.36104E-07])	4.34292E-06	0 0 sum([2.83481E-07	1.48871E-08	1.83971E-07])	8.17472E-07]/tot_ca;
total_shares_ca_eu=[sum([0.000113308	1.39886E-05	4.90749E-05])	9.54054E-05	sum([6.7615E-05	8.69784E-06	4.6869E-05])	0.000310833	0 0 sum([1.28039E-05	2.79343E-06	6.18835E-06])	3.69225E-05]/tot_ca;
total_shares_ca_us=[sum([0.004508862	0.000290908	0.002218566])	0.003796454	sum([0.009701168	0.0007585	0.00721404])	0.044597319	0 0 sum([0.001359954	9.6613E-05	0.000857377])	0.003921688]/tot_ca;
total_shares_ca_ch=[sum([0.000145445	5.05184E-05	3.04312E-05])	0.000122465	sum([2.50536E-05	1.81618E-06	1.87732E-05])	0.000115174	0 0 sum([4.72469E-08	1.51113E-08	1.80317E-08])	1.36245E-07]/tot_ca;


total_shares_ca_mne=total_shares_ca_ca_temp+total_shares_ca_in+total_shares_ca_us+total_shares_ca_eu+total_shares_ca_ch;


total_shares_ca_ca=[skill_shares_ca_ca(1,1)*total_shares_ca_mne(1,1) skill_shares_ca_ca(1,2)*total_shares_ca_mne(1,1) total_shares_ca_mne(1,2)...
    skill_shares_ca_ca(1,3)*total_shares_ca_mne(1,3) skill_shares_ca_ca(1,4)*total_shares_ca_mne(1,3) total_shares_ca_mne(1,4)...
    skill_shares_ca_ca(1,5)*total_shares_ca_mne(1,5) skill_shares_ca_ca(1,6)*total_shares_ca_mne(1,5) total_shares_ca_mne(1,6)...
    skill_shares_ca_ca(1,7)*total_shares_ca_mne(1,7) skill_shares_ca_ca(1,8)*total_shares_ca_mne(1,7) total_shares_ca_mne(1,8)];

%China

tot_ch=sum([0.032420161	0.110842798	0.166974979	0.010482383	0.1125243	0.529821138	0.020999232	0.004719658]);

total_shares_ch_ch=[0.032420161	0.110842798	0.166974979	0.010482383	0.1125243	0.529821138	0.020999232	0.004719658]/tot_ch;


%Other
total_shares_ot=[0.047782545	0.061069404	0.185860545	0.015449489	0.061995836	0.589746119	0.031105077	0.006990985]/sum([0.047782545	0.061069404	0.185860545	0.015449489	0.061995836	0.589746119	0.031105077	0.006990985]);


%Migration Shares

% mig_us=[US-IT-us US-IT-in US-IT-eu US-IT-ca US-IT-ch US-Man-us US-Man-in US-Man-eu US-Man-ca US-Man-ch US-Oth-us...
%     EU-IT-us EU-IT-in EU-IT-eu EU-IT-ca EU-IT-ch EU-Man-us EU-Man-in EU-Man-eu EU-Man-ca EU-Man-ch EU-Oth-us...
%     CA-IT-us CA-IT-in CA-IT-eu CA-IT-ca CA-IT-ch CA-Man-us CA-Man-in CA-Man-eu CA-Man-ca CA-Man-ch CA-Oth-us...
%     US-Fin-us US-Fin-in US-Fin-eu US-Fin-ca US-Fin-ch EU-Fin-us EU-Fin-in EU-Fin-eu EU-Fin-ca EU-Fin-ch CA-Fin-us CA-Fin-in CA-Fin-eu CA-Fin-ca CA-Fin-ch];

mig_us=[sum([0.155850927	5.43519E-05	0.004578039	0.000289996	4.97544E-06])	sum([0.083314639	4.70298E-05	0.024972406	0.001415822	0.000107358])	0.646061757...				
sum([0.000127469	2.64887E-06	0.001215277	4.9936E-06	2.66977E-06])	sum([7.47004E-05	2.69154E-06	0.000202083	1.18274E-06	5.19591E-06])	0.005348749...				
sum([7.96017E-05	4.85552E-09	8.24517E-07	0.00030352	4.76007E-07])	sum([0.000212184	4.54349E-09	3.30246E-07	1.88186E-05	1.32172E-07])	0.001302408...				
sum([0.064748776	8.14362E-06	0.0072297	0.00182869	7.99287E-06])	sum([0.000125308	3.6565E-06	0.000358044	3.71138E-06	1.02199E-05])	sum([2.70133E-05	1.79282E-09	6.06069E-08	4.54151E-05	1.77748E-10])]/sum([0.155850927	5.43519E-05	0.004578039	0.000289996	4.97544E-06	0.083314639	4.70298E-05	0.024972406	0.001415822	0.000107358	0.646061757...				
0.000127469	2.64887E-06	0.001215277	4.9936E-06	2.66977E-06	7.47004E-05	2.69154E-06	0.000202083	1.18274E-06	5.19591E-06	0.005348749...				
7.96017E-05	4.85552E-09	8.24517E-07	0.00030352	4.76007E-07	0.000212184	4.54349E-09	3.30246E-07	1.88186E-05	1.32172E-07	0.001302408...				
0.064748776	8.14362E-06	0.0072297	0.00182869	7.99287E-06	0.000125308	3.6565E-06	0.000358044	3.71138E-06	1.02199E-05	2.70133E-05	1.79282E-09	6.06069E-08	4.54151E-05	1.77748E-10]);


% mig_in=[US-IT-us US-IT-in US-IT-eu US-IT-ca US-IT-ch US-Man-us US-Man-in US-Man-eu US-Man-ca US-Man-ch US-Oth-us...
%     EU-IT-us EU-IT-in EU-IT-eu EU-IT-ca EU-IT-ch EU-Man-us EU-Man-in EU-Man-eu EU-Man-ca EU-Man-ch EU-Oth-us...
%     CA-IT-us CA-IT-in CA-IT-eu CA-IT-ca CA-IT-ch CA-Man-us CA-Man-in CA-Man-eu CA-Man-ca CA-Man-ch CA-Oth-us...
%     IN-IT-us IN-IT-in IN-IT-eu IN-IT-ca IN-IT-ch IN-Man-us IN-Man-in IN-Man-eu IN-Man-ca IN-Man-ch IN-Oth-us...
%     US-Fin-us US-Fin-in US-Fin-eu US-Fin-ca US-Fin-ch EU-Fin-us EU-Fin-in EU-Fin-eu EU-Fin-ca EU-Fin-ch...
%     CA-Fin-us CA-Fin-in CA-Fin-eu CA-Fin-ca CA-Fin-ch IN-Fin-us IN-Fin-in IN-Fin-eu IN-Fin-ca IN-Fin-ch];

mig_in=[sum([0.015257803	0.000441302	0.002516658	2.86121E-05	5.93121E-07])	sum([0.004021236	2.27651E-05	0.001211233	2.86121E-05	5.93121E-07])	0.045613256...
sum([5.93332E-05	1.8339E-06	0.000723138	2.97139E-06	1.58862E-06])	sum([3.98188E-05	3.01776E-06	0.000153391	8.97758E-07	3.94394E-06])	0.006845084...
sum([6.67634E-05	1.17916E-08	1.70362E-06	0.000627135	9.8353E-07])	sum([0.00028668	4.37303E-08	2.05202E-06	0.000116931	8.21261E-07])	0.003031715...
sum([0.020888575	0.152727083	0.018877237	0.00090099	0.001159783])	sum([0.004344232	0.08931701	0.007250392	4.76707E-05	0.000446575])	0.469210371...
sum([0.002351798	9.01427E-06	0.001493052	7.80926E-05	1.12257E-05])	sum([2.52475E-05	1.38009E-06	0.000212226	2.19987E-06	6.05772E-06])...	
sum([3.19626E-05	4.63894E-09	2.54177E-07	0.000190465	7.45453E-10])	sum([0.007020802	0.114597382	0.025540714	0.000424553	0.001721128])]/sum([0.015257803	0.000441302	0.002516658	2.86121E-05	5.93121E-07	0.004021236	2.27651E-05	0.001211233	2.86121E-05	5.93121E-07	0.045613256...
5.93332E-05	1.8339E-06	0.000723138	2.97139E-06	1.58862E-06	3.98188E-05	3.01776E-06	0.000153391	8.97758E-07	3.94394E-06	0.006845084...
6.67634E-05	1.17916E-08	1.70362E-06	0.000627135	9.8353E-07	0.00028668	4.37303E-08	2.05202E-06	0.000116931	8.21261E-07	0.003031715...
0.020888575	0.152727083	0.018877237	0.00090099	0.001159783	0.004344232	0.08931701	0.007250392	4.76707E-05	0.000446575	0.469210371...
0.002351798	9.01427E-06	0.001493052	7.80926E-05	1.12257E-05	2.52475E-05	1.38009E-06	0.000212226	2.19987E-06	6.05772E-06...	
3.19626E-05	4.63894E-09	2.54177E-07	0.000190465	7.45453E-10	0.007020802	0.114597382	0.025540714	0.000424553	0.001721128]);


% 
% mig_eu=[US-IT-us US-IT-in US-IT-eu US-IT-ca US-IT-ch US-Man-us US-Man-in US-Man-eu US-Man-ca US-Man-ch US-Oth-us...
%     EU-IT-us EU-IT-in EU-IT-eu EU-IT-ca EU-IT-ch EU-Man-us EU-Man-in EU-Man-eu EU-Man-ca EU-Man-ch EU-Oth-us...
%     CA-IT-us CA-IT-in CA-IT-eu CA-IT-ca CA-IT-ch CA-Man-us CA-Man-in CA-Man-eu CA-Man-ca CA-Man-ch CA-Oth-us...
%     US-Fin-us US-Fin-in US-Fin-eu US-Fin-ca US-Fin-ch EU-Fin-us EU-Fin-in EU-Fin-eu EU-Fin-ca EU-Fin-ch CA-Fin-us CA-Fin-in CA-Fin-eu CA-Fin-ca CA-Fin-ch];

mig_eu=[sum([0.000340336	5.35887E-06	6.93837E-05	1.0284E-06	1.83279E-08])	sum([0.000204106	2.87861E-07	9.22191E-05	1.0082E-05	4.10297E-07])	0.003653257...				
sum([0.012371454	0.000324279	0.14785987	0.000628407	0.000402464])	sum([0.007756924	0.000395759	0.029164599	0.000188753	0.000745777])	0.722232284...				
sum([9.53404E-05	1.43268E-08	3.22568E-06	0.00089557	1.40451E-06])	sum([0.000195916	1.92932E-08	2.05045E-06	7.99106E-05	5.61247E-07])	0.003290472...				
sum([0.000138517	5.84345E-06	0.000295005	1.09476E-05	3.26479E-06])	sum([0.007792069	0.000579549	0.057540992	0.000627299	0.001819749])	sum([2.50838E-05	5.90068E-09	6.58202E-07	0.000149474	5.85021E-10])]/sum([0.000340336	5.35887E-06	6.93837E-05	1.0284E-06	1.83279E-08	0.000204106	2.87861E-07	9.22191E-05	1.0082E-05	4.10297E-07	0.003653257...				
0.012371454	0.000324279	0.14785987	0.000628407	0.000402464	0.007756924	0.000395759	0.029164599	0.000188753	0.000745777	0.722232284...				
9.53404E-05	1.43268E-08	3.22568E-06	0.00089557	1.40451E-06	0.000195916	1.92932E-08	2.05045E-06	7.99106E-05	5.61247E-07	0.003290472...				
0.000138517	5.84345E-06	0.000295005	1.09476E-05	3.26479E-06	0.007792069	0.000579549	0.057540992	0.000627299	0.001819749	2.50838E-05	5.90068E-09	6.58202E-07	0.000149474	5.85021E-10]);

% mig_ca=[US-IT-us US-IT-in US-IT-eu US-IT-ca US-IT-ch US-Man-us US-Man-in US-Man-eu US-Man-ca US-Man-ch US-Oth-us...
%     EU-IT-us EU-IT-in EU-IT-eu EU-IT-ca EU-IT-ch EU-Man-us EU-Man-in EU-Man-eu EU-Man-ca EU-Man-ch EU-Oth-us...
%     CA-IT-us CA-IT-in CA-IT-eu CA-IT-ca CA-IT-ch CA-Man-us CA-Man-in CA-Man-eu CA-Man-ca CA-Man-ch CA-Oth-us
%     US-Fin-us US-Fin-in US-Fin-eu US-Fin-ca US-Fin-ch EU-Fin-us EU-Fin-in EU-Fin-eu EU-Fin-ca EU-Fin-ch CA-Fin-us CA-Fin-in CA-Fin-eu CA-Fin-ca CA-Fin-ch];


mig_ca=[sum([0.002385767	4.86971E-05	0.000391687	1.09067E-05	4.0325E-08])	sum([0.001796185	3.87611E-06	0.000770198	1.09067E-05	6.82066E-06])	0.028437922...				
sum([0.00022148	5.88362E-06	0.002699347	2.6316E-05	5.93003E-06])	sum([0.000162825	8.35414E-06	0.000627238	1.72794E-05	1.61274E-05])	0.008435545...				
sum([0.007777765	1.10615E-06	0.000195456	0.068028179	0.000250892])	sum([0.017108133	1.666E-06	0.00011924	0.00645855	4.41823E-05])	0.835419221...				
sum([0.001009409	3.64274E-06	0.000850586	0.000173717	6.51274E-06])	sum([7.93678E-05	6.81323E-06	0.00066715	2.39051E-05	1.9043E-05])	sum([0.002397102	4.99674E-07	2.25686E-05	0.013245878	8.3279E-08])]/sum([0.002385767	4.86971E-05	0.000391687	1.09067E-05	4.0325E-08	0.001796185	3.87611E-06	0.000770198	1.09067E-05	6.82066E-06	0.028437922...				
0.00022148	5.88362E-06	0.002699347	2.6316E-05	5.93003E-06	0.000162825	8.35414E-06	0.000627238	1.72794E-05	1.61274E-05	0.008435545...				
0.007777765	1.10615E-06	0.000195456	0.068028179	0.000250892	0.017108133	1.666E-06	0.00011924	0.00645855	4.41823E-05	0.835419221...				
0.001009409	3.64274E-06	0.000850586	0.000173717	6.51274E-06	7.93678E-05	6.81323E-06	0.00066715	2.39051E-05	1.9043E-05	0.002397102	4.99674E-07	2.25686E-05	0.013245878	8.3279E-08]);



mig_ch=[sum([0.001236101	5.79629E-06	0.0001386	2.49331E-06	3.74686E-07])	sum([0.001021529	3.55708E-07	0.000258561	1.18846E-05	1.0985E-05])	0.009497173...
sum([7.71349E-05	2.04909E-06	0.0009401	3.86289E-06	1.37723E-05])	sum([2.97673E-05	1.52729E-06	0.00011467	6.71136E-07	2.31134E-06])	0.005140312...
sum([9.65032E-05	1.45015E-08	2.46251E-06	0.000906493	1.79936E-05])	sum([0.000300685	2.96105E-08	2.15226E-06	0.000122644	6.6133E-07])	0.002804732...
sum([0.000501674	5.93227E-06	0.000506187	8.52327E-06	0.040525276])	sum([0.004539265	4.01756E-05	0.004242703	0.000145525	0.210990129])	0.692553223...
sum([0.000700344	7.52157E-07	0.000496466	4.66301E-05	3.86618E-05])	sum([2.79398E-05	2.39846E-06	0.000234857	2.43446E-06	2.68695E-05])...	
sum([4.05784E-05	9.54561E-09	3.22693E-07	0.000241807	5.49979E-09])	sum([0.00018217	4.74227E-06	0.000330116	3.02055E-08	0.020799849])]/sum([0.001236101	5.79629E-06	0.0001386	2.49331E-06	3.74686E-07	0.001021529	3.55708E-07	0.000258561	1.18846E-05	1.0985E-05	0.009497173...
7.71349E-05	2.04909E-06	0.0009401	3.86289E-06	1.37723E-05	2.97673E-05	1.52729E-06	0.00011467	6.71136E-07	2.31134E-06	0.005140312...
9.65032E-05	1.45015E-08	2.46251E-06	0.000906493	1.79936E-05	0.000300685	2.96105E-08	2.15226E-06	0.000122644	6.6133E-07	0.002804732...
0.000501674	5.93227E-06	0.000506187	8.52327E-06	0.040525276	0.004539265	4.01756E-05	0.004242703	0.000145525	0.210990129	0.692553223...
0.000700344	7.52157E-07	0.000496466	4.66301E-05	3.86618E-05	2.79398E-05	2.39846E-06	0.000234857	2.43446E-06	2.68695E-05...	
4.05784E-05	9.54561E-09	3.22693E-07	0.000241807	5.49979E-09	0.00018217	4.74227E-06	0.000330116	3.02055E-08	0.020799849	]);

% mig_ot=[US-IT-us US-IT-in US-IT-eu US-IT-ca US-IT-ch US-Man-us US-Man-in US-Man-eu US-Man-ca US-Man-ch US-Oth-us...
%     EU-IT-us EU-IT-in EU-IT-eu EU-IT-ca EU-IT-ch EU-Man-us EU-Man-in EU-Man-eu EU-Man-ca EU-Man-ch EU-Oth-us...
%     CA-IT-us CA-IT-in CA-IT-eu CA-IT-ca CA-IT-ch CA-Man-us CA-Man-in CA-Man-eu CA-Man-ca CA-Man-ch CA-Oth-us...
%     OT-IT-ot OT-Man-ot OT-Oth-ot...
%     US-Fin-us US-Fin-in US-Fin-eu US-Fin-ca US-Fin-ch EU-Fin-us EU-Fin-in EU-Fin-eu EU-Fin-ca EU-Fin-ch...
%     CA-Fin-us CA-Fin-in CA-Fin-eu CA-Fin-ca CA-Fin-ch OT-Fin-ot];

mig_ot=[sum([0.000483454	3.47972E-06	7.83197E-05	1.0225E-06	3.33367E-08])	sum([0.000255626	2.66009E-07	0.000107788	8.20395E-06	1.1018E-06])	0.004990327...					
sum([0.000346848	9.21401E-06	0.004227294	1.737E-05	9.28669E-06])	sum([0.000230036	1.18026E-05	0.000886152	5.18642E-06	2.27845E-05])	0.027156103...					
sum([0.000107793	1.61981E-08	2.7506E-06	0.001012546	1.58797E-06])	sum([0.000388578	3.8266E-08	2.78139E-06	0.000158494	1.11317E-06])	0.004899538...					
0.055729448	0.108463343	0.754646221...													
sum([0.000158968	1.38458E-06	0.000203973	1.10834E-05	2.63016E-06])	sum([0.000149396	1.28247E-05	0.001255791	1.30172E-05	3.5845E-05])	sum([4.49591E-05	1.05761E-08	3.5753E-07	0.000267912	1.04857E-09])	0.0335759]/sum([0.000483454	3.47972E-06	7.83197E-05	1.0225E-06	3.33367E-08	0.000255626	2.66009E-07	0.000107788	8.20395E-06	1.1018E-06	0.004990327...					
0.000346848	9.21401E-06	0.004227294	1.737E-05	9.28669E-06	0.000230036	1.18026E-05	0.000886152	5.18642E-06	2.27845E-05	0.027156103...					
0.000107793	1.61981E-08	2.7506E-06	0.001012546	1.58797E-06	0.000388578	3.8266E-08	2.78139E-06	0.000158494	1.11317E-06	0.004899538...					
0.055729448	0.108463343	0.754646221...													
0.000158968	1.38458E-06	0.000203973	1.10834E-05	2.63016E-06	0.000149396	1.28247E-05	0.001255791	1.30172E-05	3.5845E-05	4.49591E-05	1.05761E-08	3.5753E-07	0.000267912	1.04857E-09	0.0335759]);

%Foreign non-source share

%Foreign_IT_us_us=[India Europe Canada China Other];
Foreign_IT_us_us=[7.69E-01	3.28E-02	3.19E-02	6.20E-02	1.04E-01]/sum([7.69E-01	3.28E-02	3.19E-02	6.20E-02	1.04E-01]);
%Foreign_IT_us_in=[Europe Canada China Other];
%Foreign_IT_us_in=[2.33E-01	0.301364259	0.119858834	0.345971215]/sum([2.33E-01	0.301364259	0.119858834	0.345971215]);
%Foreign_IT_us_eu=[India Canada China Other];
%Foreign_IT_us_eu=[8.22E-01	3.34E-02	4.10E-02	1.03E-01]/sum([8.22E-01	3.34E-02	4.10E-02	1.03E-01]);
%Foreign_IT_us_ca=[India Europe China Other];
%Foreign_IT_us_ca=[0.776490304	0.056800807	0.060835961	0.105872928]/sum([0.776490304	0.056800807	0.060835961	0.105872928]);
%Foreign_IT_us_ch=[India Europe Canada Other];
%Foreign_IT_us_ch=[7.94E-01	3.69E-02	9.04E-03	1.61E-01]/sum([7.94E-01	3.69E-02	9.04E-03	1.61E-01]);
%Foreign_Man_us_us=[India Europe Canada China Other];
Foreign_Man_us_us=[6.13E-01	5.13E-02	5.55E-02	1.33E-01	1.48E-01]/sum([6.13E-01	5.13E-02	5.55E-02	1.33E-01	1.48E-01]);
%Foreign_Man_us_in=[Europe Canada China Other];
%Foreign_Man_us_in=[0.15846123	0.285230215	0.092383176	0.463925379]/sum([0.15846123	0.285230215	0.092383176	0.463925379]);
%Foreign_Man_us_eu=[India Canada China Other];
%Foreign_Man_us_eu=[6.13E-01	8.16E-02	1.07E-01	1.98E-01]/sum([6.13E-01	8.16E-02	1.07E-01	1.98E-01]);
%Foreign_Man_us_ca=[India Europe China Other];
%Foreign_Man_us_ca=[0.450295614	0.115933655	0.109376745	0.324393985]/sum([0.450295614	0.115933655	0.109376745	0.324393985]);
%Foreign_Man_us_ch=[India Europe Canada Other];
%Foreign_Man_us_ch=[9.04E-01	1.14E-02	2.14E-02	6.33E-02]/sum([9.04E-01	1.14E-02	2.14E-02	6.33E-02]);
%Foreign_Oth_us_us=[India Europe Canada China Other];
Foreign_Oth_us_us=[5.55E-01	7.22E-02	7.21E-02	9.35E-02	2.07E-01]/sum([5.55E-01	7.22E-02	7.21E-02	9.35E-02	2.07E-01]);
%Foreign_Fin_us_us=[India Europe Canada China Other];
Foreign_Fin_us_us=[5.92E-01	6.04E-02	5.67E-02	1.38E-01	1.53E-01]/sum([5.92E-01	6.04E-02	5.67E-02	1.38E-01	1.53E-01]);
%Foreign_Fin_us_in=[Europe Canada China Other];
%Foreign_Fin_us_in=[5.45E-01	4.55E-02	4.55E-02	3.64E-01]/sum([5.45E-01	4.55E-02	4.55E-02	3.64E-01]);
%Foreign_Fin_us_eu=[India Canada China Other];
%Foreign_Fin_us_eu=[5.33E-01	6.34E-02	1.32E-01	2.72E-01]/sum([5.33E-01	6.34E-02	1.32E-01	2.72E-01]);
%Foreign_Fin_us_ca=[India Europe China Other];
%Foreign_Fin_us_ca=[4.67E-01	8.93E-02	2.16E-01	2.28E-01]/sum([4.67E-01	8.93E-02	2.16E-01	2.28E-01]);
%Foreign_Fin_us_ch=[India Europe Canada Other];
%Foreign_Fin_us_ch=[2.86E-01	2.53E-01	6.24E-02	3.99E-01]/sum([2.86E-01	2.53E-01	6.24E-02	3.99E-01]);

%Foreign_IT_eu_us=[India Canada China Other];
%Foreign_IT_eu_us=[0.040775758	0.026908212	0.045385793	0.886930237]/sum([0.040775758	0.026908212	0.045385793	0.886930237]);
%Foreign_IT_eu_in=[US Canada China Other];
%Foreign_IT_eu_in=[0.073745025	0.025983356	0.043825848	0.85644577]/sum([0.073745025	0.025983356	0.043825848	0.85644577]);
%Foreign_IT_eu_eu=[India US Canada China Other];
Foreign_IT_eu_eu=[0.037882662	0.070951367	0.024999038	0.042165609	0.824001324]/sum([0.037882662	0.070951367	0.024999038	0.042165609	0.824001324]);
%Foreign_IT_eu_ca=[India US China Other];
%Foreign_IT_eu_ca=[0.038853974	0.072770561	0.043246735	0.845128729]/sum([0.038853974	0.072770561	0.043246735	0.845128729]);
%Foreign_IT_eu_ch=[India US Canada Other];
%Foreign_IT_eu_ch=[0.039550326	0.074074775	0.026099541	0.860275358]/sum([0.039550326	0.074074775	0.026099541	0.860275358]);
%Foreign_Man_eu_us=[India Canada China Other];
%Foreign_Man_eu_us=[0.041913227	0.03029909	0.026826723	0.900960961]/sum([0.041913227	0.03029909	0.026826723	0.900960961]);
%Foreign_Man_eu_in=[US Canada China Other];
%Foreign_Man_eu_in=[0.060354263	0.0297159	0.026310368	0.883619469]/sum([0.060354263	0.0297159	0.026310368	0.883619469]);
%Foreign_Man_eu_eu=[India US Canada China Other];
Foreign_Man_eu_eu=[0.039483464	0.057971268	0.028542613	0.025271544	0.848731112]/sum([0.039483464	0.057971268	0.028542613	0.025271544	0.848731112]);
%Foreign_Man_eu_ca=[India US China Other];
%Foreign_Man_eu_ca=[0.040643536	0.059674535	0.026014053	0.873667876]/sum([0.040643536	0.059674535	0.026014053	0.873667876]);
%Foreign_Man_eu_ch=[India US Canada Other];
%Foreign_Man_eu_ch=[0.040507142	0.059474274	0.02928263	0.870735954]/sum([0.040507142	0.059474274	0.02928263	0.870735954]);
%Foreign_Oth_eu_eu=[India US Canada China Other];
Foreign_Oth_eu_eu=[0.057164725	0.049781489	0.012453975	0.036753936	0.843845874]/sum([0.057164725	0.049781489	0.012453975	0.036753936	0.843845874]);
%Foreign_Fin_eu_us=[India Canada China Other];
%Foreign_Fin_eu_us=[0.040782071	0.022664175	0.03864014	0.897913614]/sum([0.040782071	0.022664175	0.03864014	0.897913614]);
%Foreign_Fin_eu_in=[US Canada China Other];
%Foreign_Fin_eu_in=[0.0740213	0.021878807	0.037301165	0.866798728]/sum([0.0740213	0.021878807	0.037301165	0.866798728]);
%Foreign_Fin_eu_eu=[India US Canada China Other];
Foreign_Fin_eu_eu=[0.035239243	0.066256775	0.089240388	0.033388429	0.775875165]/sum([0.035239243	0.066256775	0.089240388	0.033388429	0.775875165]);
%Foreign_Fin_eu_ca=[India US China Other];
%Foreign_Fin_eu_ca=[0.039287638	0.073868561	0.021833661	0.86501014]/sum([0.039287638	0.073868561	0.021833661	0.86501014]);
%Foreign_Fin_eu_ch=[India US Canada Other];
%Foreign_Fin_eu_ch=[0.039287638	0.073868561	0.021833661	0.86501014]/sum([0.039287638	0.073868561	0.021833661	0.86501014]);



%Foreign_IT_ca_us=[India Europe China Other];
%Foreign_IT_ca_us=[0.098680748	0.186361828	0.122123992	0.592833431]/sum([0.098680748	0.186361828	0.122123992	0.592833431]);
%Foreign_IT_ca_in=[Europe US China Other];
%Foreign_IT_ca_in=[0.195236225	0.055760668	0.127939436	0.621063671]/sum([0.195236225	0.055760668	0.127939436	0.621063671]);
%Foreign_IT_ca_eu=[India US China Other];
%Foreign_IT_ca_eu=[0.113836448	0.061400715	0.140880179	0.683882657]/sum([0.113836448	0.061400715	0.140880179	0.683882657]);
%Foreign_IT_ca_ca=[India Europe US China Other];
Foreign_IT_ca_ca=[0.093693794	0.176943802	0.050536239	0.115952305	0.562873859]/sum([0.093693794	0.176943802	0.050536239	0.115952305	0.562873859]);
%Foreign_IT_ca_ch=[India Europe US Other];
%Foreign_IT_ca_ch=[0.105982737	0.200151873	0.057164607	0.636700783]/sum([0.105982737	0.200151873	0.057164607	0.636700783]);
%Foreign_Man_ca_us=[India Europe China Other];
%Foreign_Man_ca_us=[0.127466249	0.115200429	0.114465332	0.64286799]/sum([0.127466249	0.115200429	0.114465332	0.64286799]);
%Foreign_Man_ca_in=[Europe US China Other];
%Foreign_Man_ca_in=[0.128658639	0.025533101	0.127837665	0.717970595]/sum([0.128658639	0.025533101	0.127837665	0.717970595]);
%Foreign_Man_ca_eu=[India US China Other];
%Foreign_Man_ca_eu=[0.140433637	0.025188056	0.126110112	0.708268195]/sum([0.140433637	0.025188056	0.126110112	0.708268195]);
%Foreign_Man_ca_ca=[India Europe US China Other];
Foreign_Man_ca_ca=[0.124617221	0.112625557	0.022351237	0.11190689	0.628499095]/sum([0.124617221	0.112625557	0.022351237	0.11190689	0.628499095]);
%Foreign_Man_ca_ch=[India Europe US Other];
%Foreign_Man_ca_ch=[0.140319995	0.126817285	0.025167673	0.707695047]/sum([0.140319995	0.126817285	0.025167673	0.707695047]);
%Foreign_Oth_ca_ca=[India Europe US China Other];
Foreign_Oth_ca_ca=[0.102886028	0.14767677	0.049258521	0.081493777	0.618684903]/sum([0.102886028	0.14767677	0.049258521	0.081493777	0.618684903]);
%Foreign_Fin_ca_us=[India Europe China Other];
%Foreign_Fin_ca_us=[0.119635937	0.124164863	0.130040877	0.626158323]/sum([0.119635937	0.124164863	0.130040877	0.626158323]);
%Foreign_Fin_ca_in=[Europe US China Other];
%Foreign_Fin_ca_in=[0.136122444	0.034853302	0.142564341	0.686459913]/sum([0.136122444	0.034853302	0.142564341	0.686459913]);
%Foreign_Fin_ca_eu=[India US China Other];
%Foreign_Fin_ca_eu=[0.13181182	0.035027215	0.143275717	0.689885249]/sum([0.13181182	0.035027215	0.143275717	0.689885249]);
%Foreign_Fin_ca_ca=[India Europe US China Other];
Foreign_Fin_ca_ca=[0.115949706	0.120339086	0.030812072	0.126034048	0.606865088]/sum([0.115949706	0.120339086	0.030812072	0.126034048	0.606865088]);
%Foreign_Fin_ca_ch=[India Europe US Other];
%Foreign_Fin_ca_ch=[0.132670736	0.137693106	0.03525546	0.694380699]/sum([0.132670736	0.137693106	0.03525546	0.694380699]);

Share_World_GDP=[0.183080478	0.026160154	0.241953416	0.022539325	0.171593075	0.354673553]/sum([0.183080478	0.026160154	0.241953416	0.022539325	0.171593075	0.354673553]);
share_population=[0.04887797	0.147100867	0.062325864	0.005943329	0.242025331	0.49372664]/sum([0.04887797	0.147100867	0.062325864	0.005943329	0.242025331	0.49372664]);




broad_share_us=[2.48E-01	7.52E-01	4.48E-01	5.52E-01	5.48E-01	4.52E-01	3.14E-01	6.86E-01];
broad_share_eu=[0.415218196	0.584781804	0.575557262	0.424442738	0.647551157	0.352448843	0.372927626	0.627072374];
broad_share_ca=[0.351042805	0.648957195	0.716180871	0.283819129	0.583200428	0.416799572	0.628915901	0.371084099];
broad_share_in=[0.244330098	0.755669902	0.503763987	0.496236013	0.760367524	0.239632476	0.183509379	0.816490621];
broad_share_ch=[0.244330098	0.755669902	0.503763987	0.496236013	0.760367524	0.239632476	0.183509379	0.816490621];
broad_share_ot=[0.244330098	0.755669902	0.503763987	0.496236013	0.760367524	0.239632476	0.183509379	0.816490621];



%Rows US - IT, Man, Oth, Fin, IN- EU - CA- CH- OT -
%Columns Buy from IT Man Oth Fin

int_imp_shares=[3.49E-02	1.75E-01	2.34E-02...
6.46E-02	2.60E-01	6.22E-03...
6.15E-02	3.17E-02	2.46E-02...
6.37E-02	4.17E-03	8.77E-02...
4.29E-02	1.40E-01	1.94E-02...
2.21E-02	3.70E-01	3.37E-02...
9.07E-03	3.54E-02	2.09E-02...
2.37E-02	1.06E-02	8.74E-02...
2.50E-02	2.00E-01	2.30E-02...
4.88E-02	3.31E-01	1.40E-02...
4.92E-02	3.20E-02	2.49E-02...
1.11E-01	4.46E-03	1.30E-01...
2.58E-02	2.25E-01	1.59E-02...
2.54E-02	2.88E-01	1.87E-02...
4.89E-02	3.66E-02	2.38E-02...
1.04E-01	5.98E-03	1.45E-01...
1.62E-01	2.59E-01	3.13E-02...
2.49E-02	3.24E-01	1.37E-02...
2.81E-02	7.95E-02	2.21E-02...
7.52E-02	5.14E-03	1.69E-01...
4.82E-02	2.00E-01	2.68E-02...
3.49E-02	3.44E-01	1.48E-02...
3.37E-02	4.47E-02	2.30E-02...
1.07E-01	6.16E-03	1.38E-01];



gamma_us_IT_Man=int_imp_shares(1,1);
gamma_us_IT_Oth=int_imp_shares(1,2);
gamma_us_IT_Fin=int_imp_shares(1,3);
gamma_us_IT_L=1-int_imp_shares(1,1)-int_imp_shares(1,2)-int_imp_shares(1,3);

gamma_us_Man_IT=int_imp_shares(1,4);
gamma_us_Man_Oth=int_imp_shares(1,5);
gamma_us_Man_Fin=int_imp_shares(1,6);
gamma_us_Man_L=1-int_imp_shares(1,4)-int_imp_shares(1,5)-int_imp_shares(1,6);

gamma_us_Oth_IT=int_imp_shares(1,7);
gamma_us_Oth_Man=int_imp_shares(1,8);
gamma_us_Oth_Fin=int_imp_shares(1,9);
gamma_us_Oth_L=1-int_imp_shares(1,7)-int_imp_shares(1,8)-int_imp_shares(1,9);

gamma_us_Fin_IT=int_imp_shares(1,10);
gamma_us_Fin_Man=int_imp_shares(1,11);
gamma_us_Fin_Oth=int_imp_shares(1,12);
gamma_us_Fin_L=1-int_imp_shares(1,10)-int_imp_shares(1,11)-int_imp_shares(1,12);




gamma_in_IT_Man=int_imp_shares(1,13);
gamma_in_IT_Oth=int_imp_shares(1,14);
gamma_in_IT_Fin=int_imp_shares(1,15);
gamma_in_IT_L=1-int_imp_shares(1,13)-int_imp_shares(1,14)-int_imp_shares(1,15);

gamma_in_Man_IT=int_imp_shares(1,16);
gamma_in_Man_Oth=int_imp_shares(1,17);
gamma_in_Man_Fin=int_imp_shares(1,18);
gamma_in_Man_L=1-int_imp_shares(1,16)-int_imp_shares(1,17)-int_imp_shares(1,18);

gamma_in_Oth_IT=int_imp_shares(1,19);
gamma_in_Oth_Man=int_imp_shares(1,20);
gamma_in_Oth_Fin=int_imp_shares(1,21);
gamma_in_Oth_L=1-int_imp_shares(1,19)-int_imp_shares(1,20)-int_imp_shares(1,21);

gamma_in_Fin_IT=int_imp_shares(1,22);
gamma_in_Fin_Man=int_imp_shares(1,23);
gamma_in_Fin_Oth=int_imp_shares(1,24);
gamma_in_Fin_L=1-int_imp_shares(1,22)-int_imp_shares(1,23)-int_imp_shares(1,24);


gamma_eu_IT_Man=int_imp_shares(1,25);
gamma_eu_IT_Oth=int_imp_shares(1,26);
gamma_eu_IT_Fin=int_imp_shares(1,27);
gamma_eu_IT_L=1-int_imp_shares(1,25)-int_imp_shares(1,26)-int_imp_shares(1,27);

gamma_eu_Man_IT=int_imp_shares(1,28);
gamma_eu_Man_Oth=int_imp_shares(1,29);
gamma_eu_Man_Fin=int_imp_shares(1,30);
gamma_eu_Man_L=1-int_imp_shares(1,28)-int_imp_shares(1,29)-int_imp_shares(1,30);

gamma_eu_Oth_IT=int_imp_shares(1,31);
gamma_eu_Oth_Man=int_imp_shares(1,32);
gamma_eu_Oth_Fin=int_imp_shares(1,33);
gamma_eu_Oth_L=1-int_imp_shares(1,31)-int_imp_shares(1,32)-int_imp_shares(1,33);

gamma_eu_Fin_IT=int_imp_shares(1,34);
gamma_eu_Fin_Man=int_imp_shares(1,35);
gamma_eu_Fin_Oth=int_imp_shares(1,36);
gamma_eu_Fin_L=1-int_imp_shares(1,34)-int_imp_shares(1,35)-int_imp_shares(1,36);


gamma_ca_IT_Man=int_imp_shares(1,37);
gamma_ca_IT_Oth=int_imp_shares(1,38);
gamma_ca_IT_Fin=int_imp_shares(1,39);
gamma_ca_IT_L=1-int_imp_shares(1,37)-int_imp_shares(1,38)-int_imp_shares(1,39);

gamma_ca_Man_IT=int_imp_shares(1,40);
gamma_ca_Man_Oth=int_imp_shares(1,41);
gamma_ca_Man_Fin=int_imp_shares(1,42);
gamma_ca_Man_L=1-int_imp_shares(1,40)-int_imp_shares(1,41)-int_imp_shares(1,42);

gamma_ca_Oth_IT=int_imp_shares(1,43);
gamma_ca_Oth_Man=int_imp_shares(1,44);
gamma_ca_Oth_Fin=int_imp_shares(1,45);
gamma_ca_Oth_L=1-int_imp_shares(1,43)-int_imp_shares(1,44)-int_imp_shares(1,45);

gamma_ca_Fin_IT=int_imp_shares(1,46);
gamma_ca_Fin_Man=int_imp_shares(1,47);
gamma_ca_Fin_Oth=int_imp_shares(1,48);
gamma_ca_Fin_L=1-int_imp_shares(1,46)-int_imp_shares(1,47)-int_imp_shares(1,48);

gamma_ch_IT_Man=int_imp_shares(1,49);
gamma_ch_IT_Oth=int_imp_shares(1,50);
gamma_ch_IT_Fin=int_imp_shares(1,51);
gamma_ch_IT_L=1-int_imp_shares(1,49)-int_imp_shares(1,50)-int_imp_shares(1,51);

gamma_ch_Man_IT=int_imp_shares(1,52);
gamma_ch_Man_Oth=int_imp_shares(1,53);
gamma_ch_Man_Fin=int_imp_shares(1,54);
gamma_ch_Man_L=1-int_imp_shares(1,52)-int_imp_shares(1,53)-int_imp_shares(1,54);

gamma_ch_Oth_IT=int_imp_shares(1,55);
gamma_ch_Oth_Man=int_imp_shares(1,56);
gamma_ch_Oth_Fin=int_imp_shares(1,57);
gamma_ch_Oth_L=1-int_imp_shares(1,55)-int_imp_shares(1,56)-int_imp_shares(1,57);

gamma_ch_Fin_IT=int_imp_shares(1,58);
gamma_ch_Fin_Man=int_imp_shares(1,59);
gamma_ch_Fin_Oth=int_imp_shares(1,60);
gamma_ch_Fin_L=1-int_imp_shares(1,58)-int_imp_shares(1,59)-int_imp_shares(1,60);


gamma_ot_IT_Man=int_imp_shares(1,61);
gamma_ot_IT_Oth=int_imp_shares(1,62);
gamma_ot_IT_Fin=int_imp_shares(1,63);
gamma_ot_IT_L=1-int_imp_shares(1,61)-int_imp_shares(1,62)-int_imp_shares(1,63);

gamma_ot_Man_IT=int_imp_shares(1,64);
gamma_ot_Man_Oth=int_imp_shares(1,65);
gamma_ot_Man_Fin=int_imp_shares(1,66);
gamma_ot_Man_L=1-int_imp_shares(1,64)-int_imp_shares(1,65)-int_imp_shares(1,66);

gamma_ot_Oth_IT=int_imp_shares(1,67);
gamma_ot_Oth_Man=int_imp_shares(1,68);
gamma_ot_Oth_Fin=int_imp_shares(1,69);
gamma_ot_Oth_L=1-int_imp_shares(1,67)-int_imp_shares(1,68)-int_imp_shares(1,69);

gamma_ot_Fin_IT=int_imp_shares(1,70);
gamma_ot_Fin_Man=int_imp_shares(1,71);
gamma_ot_Fin_Oth=int_imp_shares(1,72);
gamma_ot_Fin_L=1-int_imp_shares(1,70)-int_imp_shares(1,71)-int_imp_shares(1,72);

%Equations

wage=ones(1,198);

adjust2=0.5;
max_iter2 = 10^(6);
omega_tol2 = 10^(-3);
omega_crit2 = 10^3;
omega_iter2 = 0;


while omega_crit2 > omega_tol2 & omega_iter2 < max_iter2
    omega_iter2 = omega_iter2 + 1;


%Migration costs


% phi_in_us_us=1;
% phi_in_us_in=mig_cost_change1;
% phi_in_us_eu=1;
% phi_in_us_ca=1;
% phi_in_us_ch=1;


phi_in_us_us=mig_cost_change;
phi_in_us_in=mig_cost_change;
phi_in_us_eu=mig_cost_change;
phi_in_us_ca=mig_cost_change;
phi_in_us_ch=mig_cost_change;


phi_in_eu_us=1;
phi_in_eu_in=1;
phi_in_eu_eu=1;
phi_in_eu_ca=1;
phi_in_eu_ch=1;

phi_in_ca_us=1;
phi_in_ca_in=1;
phi_in_ca_eu=1;
phi_in_ca_ca=1;
phi_in_ca_ch=1;



% phi_ch_us_us=1;
% phi_ch_us_in=1;
% phi_ch_us_eu=1;
% phi_ch_us_ca=1;
% phi_ch_us_ch=mig_cost_change2;


phi_ch_us_us=mig_cost_change;
phi_ch_us_in=mig_cost_change;
phi_ch_us_eu=mig_cost_change;
phi_ch_us_ca=mig_cost_change;
phi_ch_us_ch=mig_cost_change;


phi_ch_eu_us=1;
phi_ch_eu_in=1;
phi_ch_eu_eu=1;
phi_ch_eu_ca=1;
phi_ch_eu_ch=1;

phi_ch_ca_us=1;
phi_ch_ca_in=1;
phi_ch_ca_eu=1;
phi_ch_ca_ca=1;
phi_ch_ca_ch=1;


% phi_ot_us_us=1;
% phi_ot_us_in=1;
% phi_ot_us_eu=1;
% phi_ot_us_ca=1;
% phi_ot_us_ch=1;


phi_ot_us_us=mig_cost_change;
phi_ot_us_in=mig_cost_change;
phi_ot_us_eu=mig_cost_change;
phi_ot_us_ca=mig_cost_change;
phi_ot_us_ch=mig_cost_change;


phi_ot_eu_us=1;
phi_ot_eu_in=1;
phi_ot_eu_eu=1;
phi_ot_eu_ca=1;
phi_ot_eu_ch=1;

phi_ot_ca_us=1;
phi_ot_ca_in=1;
phi_ot_ca_eu=1;
phi_ot_ca_ca=1;
phi_ot_ca_ch=1;

phi_us_eu_us=1;
phi_us_eu_in=1;
phi_us_eu_eu=1;
phi_us_eu_ca=1;
phi_us_eu_ch=1;

phi_us_ca_us=1;
phi_us_ca_in=1;
phi_us_ca_eu=1;
phi_us_ca_ca=1;
phi_us_ca_ch=1;


phi_eu_ca_us=1;
phi_eu_ca_in=1;
phi_eu_ca_eu=1;
phi_eu_ca_ca=1;
phi_eu_ca_ch=1;

% phi_eu_us_us=1;
% phi_eu_us_in=1;
% phi_eu_us_eu=mig_cost_change3;
% phi_eu_us_ca=1;
% phi_eu_us_ch=1;

phi_eu_us_us=mig_cost_change;
phi_eu_us_in=mig_cost_change;
phi_eu_us_eu=mig_cost_change;
phi_eu_us_ca=mig_cost_change;
phi_eu_us_ch=mig_cost_change;

% phi_ca_us_us=1;
% phi_ca_us_in=1;
% phi_ca_us_eu=1;
% phi_ca_us_ca=mig_cost_change4;
% phi_ca_us_ch=1;


phi_ca_us_us=mig_cost_change;
phi_ca_us_in=mig_cost_change;
phi_ca_us_eu=mig_cost_change;
phi_ca_us_ca=mig_cost_change;
phi_ca_us_ch=mig_cost_change;

phi_ca_eu_us=1;
phi_ca_eu_in=1;
phi_ca_eu_eu=1;
phi_ca_eu_ca=1;
phi_ca_eu_ch=1;



ajust=0.01;
max_iter = 10^(6);
omega_tol = 10^(-5);
omega_crit = 10^3;
omega_iter = 0;




while omega_crit > omega_tol & omega_iter < max_iter
    omega_iter = omega_iter + 1;

w_us_IT_us_d=wage(1,1);
w_us_IT_us_f=wage(1,2);
w_us_Man_us_d=wage(1,3);
w_us_Man_us_f=wage(1,4);
w_us_Oth_us_d=wage(1,5);
w_us_Oth_us_f=wage(1,6);

w_eu_IT_eu_d=wage(1,31);
w_eu_IT_eu_f=wage(1,32);
w_eu_Man_eu_d=wage(1,33);
w_eu_Man_eu_f=wage(1,34);
w_eu_Oth_eu_d=wage(1,35);
w_eu_Oth_eu_f=wage(1,36);

w_ca_IT_ca_d=wage(1,61);
w_ca_IT_ca_f=wage(1,62);
w_ca_Man_ca_d=wage(1,63);
w_ca_Man_ca_f=wage(1,64);
w_ca_Oth_ca_d=wage(1,65);
w_ca_Oth_ca_f=wage(1,66);


w_in_IT_in=wage(1,92);


w_in_Man_in=wage(1,97);

w_in_Oth_in=wage(1,101);

w_ch_IT_ch=wage(1,106);

w_ch_Man_ch=wage(1,111);
w_ch_Oth_ch=wage(1,112);
w_ot_IT_ot=wage(1,113);
w_ot_Man_ot=wage(1,114);
w_ot_Oth_ot=wage(1,115);

w_us_L=wage(1,116);
w_in_L=wage(1,117);
w_eu_L=wage(1,118);
w_ca_L=wage(1,119);
w_ch_L=wage(1,120);
w_ot_L=wage(1,121);


p_us_IT_alt=wage(1,122); 
p_us_Man_alt=wage(1,123); 
p_us_Oth_alt=wage(1,124); 
p_in_IT_alt=wage(1,125); 
p_in_Man_alt=wage(1,126); 
p_in_Oth_alt=wage(1,127); 
p_eu_IT_alt=wage(1,128); 
p_eu_Man_alt=wage(1,129); 
p_eu_Oth_alt=wage(1,130); 
p_ca_IT_alt=wage(1,131); 
p_ca_Man_alt=wage(1,132); 
p_ca_Oth_alt=wage(1,133); 
p_ch_IT_alt=wage(1,134); 
p_ch_Man_alt=wage(1,135); 
p_ch_Oth_alt=wage(1,136); 
p_ot_IT_alt=wage(1,137); 
p_ot_Man_alt=wage(1,138); 
p_ot_Oth_alt=wage(1,139);



w_us_Fin_us_d=wage(1,140);
w_us_Fin_us_f=wage(1,141);

w_eu_Fin_eu_d=wage(1,154);
w_eu_Fin_eu_f=wage(1,155);

w_ca_Fin_ca_d=wage(1,168);
w_ca_Fin_ca_f=wage(1,169);


w_in_Fin_in=wage(1,183);

w_ch_Fin_ch=wage(1,191);
w_ot_Fin_ot=wage(1,192);
p_us_Fin_alt=wage(1,193); 
p_in_Fin_alt=wage(1,194); 
p_eu_Fin_alt=wage(1,195); 
p_ca_Fin_alt=wage(1,196);
p_ch_Fin_alt=wage(1,197); 
p_ot_Fin_alt=wage(1,198);





%Migration probabilities


%Consumption shares by sector
gamma=[1.22E-01	9.68E-02	7.15E-01	6.57E-02]/sum([1.22E-01	9.68E-02	7.15E-01	6.57E-02]);
gamma_eu=[1.06E-01	9.57E-02	7.46E-01	5.24E-02]/sum([1.06E-01	9.57E-02	7.46E-01	5.24E-02]);
gamma_in=[2.15E-02	1.18E-01	8.28E-01	3.27E-02]/sum([2.15E-02	1.18E-01	8.28E-01	3.27E-02]);
gamma_ch=[4.38E-02	2.24E-01	7.06E-01	2.69E-02]/sum([4.38E-02	2.24E-01	7.06E-01	2.69E-02]);
gamma_ot=[6.69E-02	1.29E-01	7.62E-01	4.13E-02]/sum([6.69E-02	1.29E-01	7.62E-01	4.13E-02]);
gamma_ca=[8.61E-02	9.07E-02	7.66E-01	5.68E-02]/sum([8.61E-02	9.07E-02	7.66E-01	5.68E-02]);

price_deflator_us=p_us_IT_alt^gamma(1,1)*p_us_Man_alt^gamma(1,2)*p_us_Oth_alt^gamma(1,3)*p_us_Fin_alt^gamma(1,4);
price_deflator_in=p_in_IT_alt^gamma_in(1,1)*p_in_Man_alt^gamma_in(1,2)*p_in_Oth_alt^gamma_in(1,3)*p_in_Fin_alt^gamma_in(1,4);
price_deflator_eu=p_eu_IT_alt^gamma_eu(1,1)*p_eu_Man_alt^gamma_eu(1,2)*p_eu_Oth_alt^gamma_eu(1,3)*p_eu_Fin_alt^gamma_eu(1,4);
price_deflator_ca=p_ca_IT_alt^gamma_ca(1,1)*p_ca_Man_alt^gamma_ca(1,2)*p_ca_Oth_alt^gamma_ca(1,3)*p_ca_Fin_alt^gamma_ca(1,4);
price_deflator_ch=p_ch_IT_alt^gamma_ch(1,1)*p_ch_Man_alt^gamma_ch(1,2)*p_ch_Oth_alt^gamma_ch(1,3)*p_ch_Fin_alt^gamma_ch(1,4);
price_deflator_ot=p_ot_IT_alt^gamma_ot(1,1)*p_ot_Man_alt^gamma_ot(1,2)*p_ot_Oth_alt^gamma_ot(1,3)*p_ot_Fin_alt^gamma_ot(1,4);



%US workers
us_options=A_us_IT*(w_us_IT_us_d/price_deflator_us)^kappa*mig_us(1,1)+A_us_Man*(w_us_Man_us_d/price_deflator_us)^kappa*mig_us(1,2)...
    +A_us_Oth*(w_us_Oth_us_d/price_deflator_us)^kappa*mig_us(1,3)...
    +A_us_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)*mig_us(1,4)...
    +A_us_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)*mig_us(1,5)+A_us_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)*mig_us(1,6)...
    +A_us_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)*mig_us(1,7)+A_us_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)*mig_us(1,8)...
    +A_us_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)*mig_us(1,9)...
    +A_us_Fin*(w_us_Fin_us_d/price_deflator_us)^kappa*mig_us(1,10)+A_us_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)*mig_us(1,11)+...
    +A_us_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)*mig_us(1,12);




mig_us_IT_us_us=A_us_IT*(w_us_IT_us_d/price_deflator_us)^kappa/us_options;
mig_us_Man_us_us=A_us_Man*(w_us_Man_us_d/price_deflator_us)^kappa/us_options;
mig_us_Oth_us_us=A_us_Oth*(w_us_Oth_us_d/price_deflator_us)^kappa/us_options;
mig_us_Fin_us_us=A_us_Fin*(w_us_Fin_us_d/price_deflator_us)^kappa/us_options;



mig_us_IT_eu_eu=A_us_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)/us_options;
mig_us_Man_eu_eu=A_us_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)/us_options;
mig_us_Oth_eu_eu=A_us_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)/us_options;
mig_us_Fin_eu_eu=A_us_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_us_eu_eu^(-kappa)/us_options;


mig_us_IT_ca_ca=A_us_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)/us_options;
mig_us_Man_ca_ca=A_us_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)/us_options;
mig_us_Oth_ca_ca=A_us_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)/us_options;
mig_us_Fin_ca_ca=A_us_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_us_ca_ca^(-kappa)/us_options;


%Europe

eu_options=A_eu_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)*mig_eu(1,1)+A_eu_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)*mig_eu(1,2)...
    +A_eu_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)*mig_eu(1,3)...
    +A_eu_IT*(w_eu_IT_eu_d/price_deflator_eu)^kappa*mig_eu(1,4)...
    +A_eu_Man*(w_eu_Man_eu_d/price_deflator_eu)^kappa*mig_eu(1,5)+A_eu_Oth*(w_eu_Oth_eu_d/price_deflator_eu)^kappa*mig_eu(1,6)...
    +A_eu_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)*mig_eu(1,7)+A_eu_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)*mig_eu(1,8)...
    +A_eu_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)*mig_eu(1,9)...
    +A_eu_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)*mig_eu(1,10)...
    +A_eu_Fin*(w_eu_Fin_eu_d/price_deflator_eu)^kappa*mig_eu(1,11)+A_eu_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)*mig_eu(1,12);



mig_eu_IT_us_us=A_eu_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)/eu_options;
mig_eu_Man_us_us=A_eu_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)/eu_options;
mig_eu_Oth_us_us=A_eu_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)/eu_options;
mig_eu_Fin_us_us=A_eu_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_eu_us_us^(-kappa)/eu_options;


mig_eu_IT_eu_eu=A_eu_IT*(w_eu_IT_eu_d/price_deflator_eu)^kappa/eu_options;
mig_eu_Man_eu_eu=A_eu_Man*(w_eu_Man_eu_d/price_deflator_eu)^kappa/eu_options;
mig_eu_Oth_eu_eu=A_eu_Oth*(w_eu_Oth_eu_d/price_deflator_eu)^kappa/eu_options;
mig_eu_Fin_eu_eu=A_eu_Fin*(w_eu_Fin_eu_d/price_deflator_eu)^kappa/eu_options;

mig_eu_IT_ca_ca=A_eu_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)/eu_options;
mig_eu_Man_ca_ca=A_eu_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)/eu_options;
mig_eu_Oth_ca_ca=A_eu_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)/eu_options;
mig_eu_Fin_ca_ca=A_eu_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_eu_ca_ca^(-kappa)/eu_options;


%Canada


ca_options=A_ca_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)*mig_ca(1,1)+A_ca_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)*mig_ca(1,2)...
    +A_ca_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)*mig_ca(1,3)...    
    +A_ca_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)*mig_ca(1,4)...
    +A_ca_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)*mig_ca(1,5)...
    +A_ca_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)*mig_ca(1,6)...
    +A_ca_IT*(w_ca_IT_ca_d/price_deflator_ca)^kappa*mig_ca(1,7)+A_ca_Man*(w_ca_Man_ca_d/price_deflator_ca)^kappa*mig_ca(1,8)...
    +A_ca_Oth*(w_ca_Oth_ca_d/price_deflator_ca)^kappa*mig_ca(1,9)...
    +A_ca_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)*mig_ca(1,10)...
    +A_ca_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)*mig_ca(1,11)+A_ca_Fin*(w_ca_Fin_ca_d/price_deflator_ca)^kappa*mig_ca(1,12);


mig_ca_IT_us_us=A_ca_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)/ca_options;
mig_ca_Man_us_us=A_ca_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)/ca_options;
mig_ca_Oth_us_us=A_ca_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)/ca_options;
mig_ca_Fin_us_us=A_ca_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_ca_us_us^(-kappa)/ca_options;


mig_ca_IT_eu_eu=A_ca_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)/ca_options;
mig_ca_Man_eu_eu=A_ca_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)/ca_options;
mig_ca_Oth_eu_eu=A_ca_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)/ca_options;
mig_ca_Fin_eu_eu=A_ca_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_ca_eu_eu^(-kappa)/ca_options;


mig_ca_IT_ca_ca=A_ca_IT*(w_ca_IT_ca_d/price_deflator_ca)^kappa/ca_options;
mig_ca_Man_ca_ca=A_ca_Man*(w_ca_Man_ca_d/price_deflator_ca)^kappa/ca_options;
mig_ca_Oth_ca_ca=A_ca_Oth*(w_ca_Oth_ca_d/price_deflator_ca)^kappa/ca_options;
mig_ca_Fin_ca_ca=A_ca_Fin*(w_ca_Fin_ca_d/price_deflator_ca)^kappa/ca_options;

%India


in_options=A_in_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)*mig_in(1,1)+A_in_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)*mig_in(1,2)...
    +A_in_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)*mig_in(1,3)...    
    +A_in_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)*mig_in(1,4)...
    +A_in_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)*mig_in(1,5)...
    +A_in_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)*mig_in(1,6)...
    +A_in_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)*mig_in(1,7)+A_in_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)*mig_in(1,8)...
    +A_in_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)*mig_in(1,9)...
    +A_in_IT*(w_in_IT_in/price_deflator_in)^kappa*mig_in(1,10)+A_in_Man*(w_in_Man_in/price_deflator_in)^kappa*mig_in(1,11)+A_in_Oth*(w_in_Oth_in/price_deflator_in)^kappa*mig_in(1,12)...
    +A_in_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)*mig_in(1,13)...
    +A_in_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)*mig_in(1,14)+A_in_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)*mig_in(1,15)...
    +A_in_Fin*(w_in_Fin_in/price_deflator_in)^kappa*mig_in(1,16);


mig_in_IT_us_us=A_in_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)/in_options;
mig_in_Man_us_us=A_in_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)/in_options;
mig_in_Oth_us_us=A_in_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)/in_options;
mig_in_Fin_us_us=A_in_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_in_us_us^(-kappa)/in_options;


mig_in_IT_eu_eu=A_in_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)/in_options;
mig_in_Man_eu_eu=A_in_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)/in_options;
mig_in_Oth_eu_eu=A_in_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)/in_options;
mig_in_Fin_eu_eu=A_in_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_in_eu_eu^(-kappa)/in_options;


mig_in_IT_ca_ca=A_in_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)/in_options;
mig_in_Man_ca_ca=A_in_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)/in_options;
mig_in_Oth_ca_ca=A_in_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)/in_options;
mig_in_Fin_ca_ca=A_in_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_in_ca_ca^(-kappa)/in_options;



mig_in_IT_in_in=A_in_IT*(w_in_IT_in/price_deflator_in)^kappa/in_options;
mig_in_Man_in_in=A_in_Man*(w_in_Man_in/price_deflator_in)^kappa/in_options;
mig_in_Oth_in_in=A_in_Oth*(w_in_Oth_in/price_deflator_in)^kappa/in_options;
mig_in_Fin_in_in=A_in_Fin*(w_in_Fin_in/price_deflator_in)^kappa/in_options;


%China


ch_options=A_ch_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)*mig_ch(1,1)+A_ch_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)*mig_ch(1,2)...
    +A_ch_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)*mig_ch(1,3)...    
    +A_ch_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)*mig_ch(1,4)...
    +A_ch_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)*mig_ch(1,5)+A_ch_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)*mig_ch(1,6)...
    +A_ch_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)*mig_ch(1,7)+A_ch_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)*mig_ch(1,8)...
    +A_ch_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)*mig_ch(1,9)...
    +A_ch_IT*(w_ch_IT_ch/price_deflator_ch)^kappa*mig_ch(1,10)+A_ch_Man*(w_ch_Man_ch/price_deflator_ch)^kappa*mig_ch(1,11)+A_ch_Oth*(w_ch_Oth_ch/price_deflator_ch)^kappa*mig_ch(1,12)...
    +A_ch_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)*mig_ch(1,13)...
    +A_ch_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)*mig_ch(1,14)+A_ch_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)*mig_ch(1,15)...
    +A_ch_Fin*(w_ch_Fin_ch/price_deflator_ch)^kappa*mig_ch(1,16);


mig_ch_IT_us_us=A_ch_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)/ch_options;
mig_ch_Man_us_us=A_ch_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)/ch_options;
mig_ch_Oth_us_us=A_ch_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)/ch_options;
mig_ch_Fin_us_us=A_ch_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_ch_us_us^(-kappa)/ch_options;

mig_ch_IT_eu_eu=A_ch_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)/ch_options;
mig_ch_Man_eu_eu=A_ch_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)/ch_options;
mig_ch_Oth_eu_eu=A_ch_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)/ch_options;
mig_ch_Fin_eu_eu=A_ch_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_ch_eu_eu^(-kappa)/ch_options;

mig_ch_IT_ca_ca=A_ch_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)/ch_options;
mig_ch_Man_ca_ca=A_ch_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)/ch_options;
mig_ch_Oth_ca_ca=A_ch_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)/ch_options;
mig_ch_Fin_ca_ca=A_ch_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_ch_ca_ca^(-kappa)/ch_options;


mig_ch_IT_ch_ch=A_ch_IT*(w_ch_IT_ch/price_deflator_ch)^kappa/ch_options;
mig_ch_Man_ch_ch=A_ch_Man*(w_ch_Man_ch/price_deflator_ch)^kappa/ch_options;
mig_ch_Oth_ch_ch=A_ch_Oth*(w_ch_Oth_ch/price_deflator_ch)^kappa/ch_options;
mig_ch_Fin_ch_ch=A_ch_Fin*(w_ch_Fin_ch/price_deflator_ch)^kappa/ch_options;


%Other


ot_options=A_ot_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)*mig_ot(1,1)+A_ot_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)*mig_ot(1,2)...
    +A_ot_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)*mig_ot(1,3)...    
    +A_ot_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)*mig_ot(1,4)...
    +A_ot_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)*mig_ot(1,5)+A_ot_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)*mig_ot(1,6)...
    +A_ot_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)*mig_ot(1,7)+A_ot_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)*mig_ot(1,8)...
    +A_ot_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)*mig_ot(1,9)...
    +A_ot_IT*(w_ot_IT_ot/price_deflator_ot)^kappa*mig_ot(1,10)+A_ot_Man*(w_ot_Man_ot/price_deflator_ot)^kappa*mig_ot(1,11)+A_ot_Oth*(w_ot_Oth_ot/price_deflator_ot)^kappa*mig_ot(1,12)...
    +A_ot_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)*mig_ot(1,13)...
    +A_ot_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)*mig_ot(1,14)+A_ot_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)*mig_ot(1,15)...
    +A_ot_Fin*(w_ot_Fin_ot/price_deflator_ot)^kappa*mig_ot(1,16);




mig_ot_IT_us_us=A_ot_IT*(w_us_IT_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)/ot_options;
mig_ot_Man_us_us=A_ot_Man*(w_us_Man_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)/ot_options;
mig_ot_Oth_us_us=A_ot_Oth*(w_us_Oth_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)/ot_options;
mig_ot_Fin_us_us=A_ot_Fin*(w_us_Fin_us_f/price_deflator_us)^kappa*phi_ot_us_us^(-kappa)/ot_options;

mig_ot_IT_eu_eu=A_ot_IT*(w_eu_IT_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)/ot_options;
mig_ot_Man_eu_eu=A_ot_Man*(w_eu_Man_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)/ot_options;
mig_ot_Oth_eu_eu=A_ot_Oth*(w_eu_Oth_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)/ot_options;
mig_ot_Fin_eu_eu=A_ot_Fin*(w_eu_Fin_eu_f/price_deflator_eu)^kappa*phi_ot_eu_eu^(-kappa)/ot_options;

mig_ot_IT_ca_ca=A_ot_IT*(w_ca_IT_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)/ot_options;
mig_ot_Man_ca_ca=A_ot_Man*(w_ca_Man_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)/ot_options;
mig_ot_Oth_ca_ca=A_ot_Oth*(w_ca_Oth_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)/ot_options;
mig_ot_Fin_ca_ca=A_ot_Fin*(w_ca_Fin_ca_f/price_deflator_ca)^kappa*phi_ot_ca_ca^(-kappa)/ot_options;

mig_ot_IT_ot_ot=A_ot_IT*(w_ot_IT_ot/price_deflator_ot)^kappa/ot_options;
mig_ot_Man_ot_ot=A_ot_Man*(w_ot_Man_ot/price_deflator_ot)^kappa/ot_options;
mig_ot_Oth_ot_ot=A_ot_Oth*(w_ot_Oth_ot/price_deflator_ot)^kappa/ot_options;
mig_ot_Fin_ot_ot=A_ot_Fin*(w_ot_Fin_ot/price_deflator_ot)^kappa/ot_options;




%Unit cost of production high-skill labor
%US
costh_us_IT_us=(psi_d^lambda*w_us_IT_us_d^(1-lambda)*skill_shares_us_us(1,1)+psi_f^lambda*w_us_IT_us_f^(1-lambda)*skill_shares_us_us(1,2))^(1/(1-lambda));
costh_us_Man_us=(psi_d^lambda*w_us_Man_us_d^(1-lambda)*skill_shares_us_us(1,3)+psi_f^lambda*w_us_Man_us_f^(1-lambda)*skill_shares_us_us(1,4))^(1/(1-lambda));
costh_us_Oth_us=(psi_d^lambda*w_us_Oth_us_d^(1-lambda)*skill_shares_us_us(1,5)+psi_f^lambda*w_us_Oth_us_f^(1-lambda)*skill_shares_us_us(1,6))^(1/(1-lambda));
costh_us_Fin_us=(psi_d^lambda*w_us_Fin_us_d^(1-lambda)*skill_shares_us_us(1,7)+psi_f^lambda*w_us_Fin_us_f^(1-lambda)*skill_shares_us_us(1,8))^(1/(1-lambda));

%Europe
costh_eu_IT_eu=(psi_d^lambda*w_eu_IT_eu_d^(1-lambda)*skill_shares_eu_eu(1,1)+psi_f^lambda*w_eu_IT_eu_f^(1-lambda)*skill_shares_eu_eu(1,2))^(1/(1-lambda));
costh_eu_Man_eu=(psi_d^lambda*w_eu_Man_eu_d^(1-lambda)*skill_shares_eu_eu(1,3)+psi_f^lambda*w_eu_Man_eu_f^(1-lambda)*skill_shares_eu_eu(1,4))^(1/(1-lambda));
costh_eu_Oth_eu=(psi_d^lambda*w_eu_Oth_eu_d^(1-lambda)*skill_shares_eu_eu(1,5)+psi_f^lambda*w_eu_Oth_eu_f^(1-lambda)*skill_shares_eu_eu(1,6))^(1/(1-lambda));
costh_eu_Fin_eu=(psi_d^lambda*w_eu_Fin_eu_d^(1-lambda)*skill_shares_eu_eu(1,7)+psi_f^lambda*w_eu_Fin_eu_f^(1-lambda)*skill_shares_eu_eu(1,8))^(1/(1-lambda));

%Canada
costh_ca_IT_ca=(psi_d^lambda*w_ca_IT_ca_d^(1-lambda)*skill_shares_ca_ca(1,1)+psi_f^lambda*w_ca_IT_ca_f^(1-lambda)*skill_shares_ca_ca(1,2))^(1/(1-lambda));
costh_ca_Man_ca=(psi_d^lambda*w_ca_Man_ca_d^(1-lambda)*skill_shares_ca_ca(1,3)+psi_f^lambda*w_ca_Man_ca_f^(1-lambda)*skill_shares_ca_ca(1,4))^(1/(1-lambda));
costh_ca_Oth_ca=(psi_d^lambda*w_ca_Oth_ca_d^(1-lambda)*skill_shares_ca_ca(1,5)+psi_f^lambda*w_ca_Oth_ca_f^(1-lambda)*skill_shares_ca_ca(1,6))^(1/(1-lambda));
costh_ca_Fin_ca=(psi_d^lambda*w_ca_Fin_ca_d^(1-lambda)*skill_shares_ca_ca(1,7)+psi_f^lambda*w_ca_Fin_ca_f^(1-lambda)*skill_shares_ca_ca(1,8))^(1/(1-lambda));



%Unit cost of production

%US


cost_us_IT_us=(p_us_Man_alt^gamma_us_IT_Man)*(p_us_Oth_alt^gamma_us_IT_Oth)*(p_us_Fin_alt^gamma_us_IT_Fin)*(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,1)+psi_h^epsilon*costh_us_IT_us^(1-epsilon)*broad_share_us(1,2))^(gamma_us_IT_L/(1-epsilon));
cost_us_Man_us=(p_us_IT_alt^gamma_us_Man_IT)*(p_us_Oth_alt^gamma_us_Man_Oth)*(p_us_Fin_alt^gamma_us_Man_Fin)*(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,3)+psi_h^epsilon*costh_us_Man_us^(1-epsilon)*broad_share_us(1,4))^(gamma_us_Man_L/(1-epsilon));
cost_us_Oth_us=(p_us_IT_alt^gamma_us_Oth_IT)*(p_us_Man_alt^gamma_us_Oth_Man)*(p_us_Fin_alt^gamma_us_Oth_Fin)*(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,5)+psi_h^epsilon*costh_us_Oth_us^(1-epsilon)*broad_share_us(1,6))^(gamma_us_Oth_L/(1-epsilon));
cost_us_Fin_us=(p_us_IT_alt^gamma_us_Fin_IT)*(p_us_Man_alt^gamma_us_Fin_Man)*(p_us_Oth_alt^gamma_us_Fin_Oth)*(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,7)+psi_h^epsilon*costh_us_Fin_us^(1-epsilon)*broad_share_us(1,8))^(gamma_us_Fin_L/(1-epsilon));

%Europe

cost_eu_IT_eu=(p_eu_Man_alt^gamma_eu_IT_Man)*(p_eu_Oth_alt^gamma_eu_IT_Oth)*(p_eu_Fin_alt^gamma_eu_IT_Fin)*(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,1)+psi_h^epsilon*costh_eu_IT_eu^(1-epsilon)*broad_share_eu(1,2))^(gamma_eu_IT_L/(1-epsilon));
cost_eu_Man_eu=(p_eu_IT_alt^gamma_eu_Man_IT)*(p_eu_Oth_alt^gamma_eu_Man_Oth)*(p_eu_Fin_alt^gamma_eu_Man_Fin)*(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,3)+psi_h^epsilon*costh_eu_Man_eu^(1-epsilon)*broad_share_eu(1,4))^(gamma_eu_Man_L/(1-epsilon));
cost_eu_Oth_eu=(p_eu_IT_alt^gamma_eu_Oth_IT)*(p_eu_Man_alt^gamma_eu_Oth_Man)*(p_eu_Fin_alt^gamma_eu_Oth_Fin)*(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,5)+psi_h^epsilon*costh_eu_Oth_eu^(1-epsilon)*broad_share_eu(1,6))^(gamma_eu_Oth_L/(1-epsilon));
cost_eu_Fin_eu=(p_eu_IT_alt^gamma_eu_Fin_IT)*(p_eu_Oth_alt^gamma_eu_Fin_Oth)*(p_eu_Man_alt^gamma_eu_Fin_Man)*(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,7)+psi_h^epsilon*costh_eu_Fin_eu^(1-epsilon)*broad_share_eu(1,8))^(gamma_eu_Fin_L/(1-epsilon));

%Canada

cost_ca_IT_ca=(p_ca_Man_alt^gamma_ca_IT_Man)*(p_ca_Oth_alt^gamma_ca_IT_Oth)*(p_ca_Fin_alt^gamma_ca_IT_Fin)*(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,1)+psi_h^epsilon*costh_ca_IT_ca^(1-epsilon)*broad_share_ca(1,2))^(gamma_ca_IT_L/(1-epsilon));
cost_ca_Man_ca=(p_ca_IT_alt^gamma_ca_Man_IT)*(p_ca_Oth_alt^gamma_ca_Man_Oth)*(p_ca_Fin_alt^gamma_ca_Man_Fin)*(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,3)+psi_h^epsilon*costh_ca_Man_ca^(1-epsilon)*broad_share_ca(1,4))^(gamma_ca_Man_L/(1-epsilon));
cost_ca_Oth_ca=(p_ca_IT_alt^gamma_ca_Oth_IT)*(p_ca_Man_alt^gamma_ca_Oth_Man)*(p_ca_Fin_alt^gamma_ca_Oth_Fin)*(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,5)+psi_h^epsilon*costh_ca_Oth_ca^(1-epsilon)*broad_share_ca(1,6))^(gamma_ca_Oth_L/(1-epsilon));
cost_ca_Fin_ca=(p_ca_IT_alt^gamma_ca_Fin_IT)*(p_ca_Oth_alt^gamma_ca_Fin_Oth)*(p_ca_Man_alt^gamma_ca_Fin_Man)*(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,7)+psi_h^epsilon*costh_ca_Fin_ca^(1-epsilon)*broad_share_ca(1,8))^(gamma_ca_Fin_L/(1-epsilon));


%India

cost_in_IT_in=(p_in_Man_alt^gamma_in_IT_Man)*(p_in_Oth_alt^gamma_in_IT_Oth)*(p_in_Fin_alt^gamma_in_IT_Fin)*(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,1)+psi_h^epsilon*w_in_IT_in^(1-epsilon)*broad_share_in(1,2))^(gamma_in_IT_L/(1-epsilon));
cost_in_Man_in=(p_in_IT_alt^gamma_in_Man_IT)*(p_in_Oth_alt^gamma_in_Man_Oth)*(p_in_Fin_alt^gamma_in_Man_Fin)*(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,3)+psi_h^epsilon*w_in_Man_in^(1-epsilon)*broad_share_in(1,4))^(gamma_in_Man_L/(1-epsilon));
cost_in_Oth_in=(p_in_IT_alt^gamma_in_Oth_IT)*(p_in_Man_alt^gamma_in_Oth_Man)*(p_in_Fin_alt^gamma_in_Oth_Fin)*(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,5)+psi_h^epsilon*w_in_Oth_in^(1-epsilon)*broad_share_in(1,6))^(gamma_in_Oth_L/(1-epsilon));
cost_in_Fin_in=(p_in_IT_alt^gamma_in_Fin_IT)*(p_in_Oth_alt^gamma_in_Fin_Oth)*(p_in_Man_alt^gamma_in_Fin_Man)*(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,7)+psi_h^epsilon*w_in_Fin_in^(1-epsilon)*broad_share_in(1,8))^(gamma_in_Fin_L/(1-epsilon));


%China

cost_ch_IT_ch=(p_ch_Man_alt^gamma_ch_IT_Man)*(p_ch_Oth_alt^gamma_ch_IT_Oth)*(p_ch_Fin_alt^gamma_ch_IT_Fin)*(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,1)+psi_h^epsilon*w_ch_IT_ch^(1-epsilon)*broad_share_ch(1,2))^(gamma_ch_IT_L/(1-epsilon));
cost_ch_Man_ch=(p_ch_IT_alt^gamma_ch_Man_IT)*(p_ch_Oth_alt^gamma_ch_Man_Oth)*(p_ch_Fin_alt^gamma_ch_Man_Fin)*(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,3)+psi_h^epsilon*w_ch_Man_ch^(1-epsilon)*broad_share_ch(1,4))^(gamma_ch_Man_L/(1-epsilon));
cost_ch_Oth_ch=(p_ch_IT_alt^gamma_ch_Oth_IT)*(p_ch_Man_alt^gamma_ch_Oth_Man)*(p_ch_Fin_alt^gamma_ch_Oth_Fin)*(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,5)+psi_h^epsilon*w_ch_Oth_ch^(1-epsilon)*broad_share_ch(1,6))^(gamma_ch_Oth_L/(1-epsilon));
cost_ch_Fin_ch=(p_ch_IT_alt^gamma_ch_Fin_IT)*(p_ch_Oth_alt^gamma_ch_Fin_Oth)*(p_ch_Man_alt^gamma_ch_Fin_Man)*(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,7)+psi_h^epsilon*w_ch_Fin_ch^(1-epsilon)*broad_share_ch(1,8))^(gamma_ch_Fin_L/(1-epsilon));


%Other
cost_ot_IT_ot=(p_ot_Man_alt^gamma_ot_IT_Man)*(p_ot_Oth_alt^gamma_ot_IT_Oth)*(p_ot_Fin_alt^gamma_ot_IT_Fin)*(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,1)+psi_h^epsilon*w_ot_IT_ot^(1-epsilon)*broad_share_ot(1,2))^(gamma_ot_IT_L/(1-epsilon));
cost_ot_Man_ot=(p_ot_IT_alt^gamma_ot_Man_IT)*(p_ot_Oth_alt^gamma_ot_Man_Oth)*(p_ot_Fin_alt^gamma_ot_Man_Fin)*(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,3)+psi_h^epsilon*w_ot_Man_ot^(1-epsilon)*broad_share_ot(1,4))^(gamma_ot_Man_L/(1-epsilon));
cost_ot_Oth_ot=(p_ot_IT_alt^gamma_ot_Oth_IT)*(p_ot_Man_alt^gamma_ot_Oth_Man)*(p_ot_Fin_alt^gamma_ot_Oth_Fin)*(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,5)+psi_h^epsilon*w_ot_Oth_ot^(1-epsilon)*broad_share_ot(1,6))^(gamma_ot_Oth_L/(1-epsilon));
cost_ot_Fin_ot=(p_ot_IT_alt^gamma_ot_Fin_IT)*(p_ot_Man_alt^gamma_ot_Fin_Man)*(p_ot_Oth_alt^gamma_ot_Fin_Oth)*(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,7)+psi_h^epsilon*w_ot_Fin_ot^(1-epsilon)*broad_share_ot(1,8))^(gamma_ot_Fin_L/(1-epsilon));





%BROAD LOW-High Skill Share

%US
lowshare_us_IT_us=(psi_l^epsilon*w_us_L^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,1)+psi_h^epsilon*costh_us_IT_us^(1-epsilon)*broad_share_us(1,2));
highshare_us_IT_us=(psi_h^epsilon*costh_us_IT_us^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,1)+psi_h^epsilon*costh_us_IT_us^(1-epsilon)*broad_share_us(1,2));

lowshare_us_Man_us=(psi_l^epsilon*w_us_L^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,3)+psi_h^epsilon*costh_us_Man_us^(1-epsilon)*broad_share_us(1,4));
highshare_us_Man_us=(psi_h^epsilon*costh_us_Man_us^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,3)+psi_h^epsilon*costh_us_Man_us^(1-epsilon)*broad_share_us(1,4));

lowshare_us_Oth_us=(psi_l^epsilon*w_us_L^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,5)+psi_h^epsilon*costh_us_Oth_us^(1-epsilon)*broad_share_us(1,6));
highshare_us_Oth_us=(psi_h^epsilon*costh_us_Oth_us^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,5)+psi_h^epsilon*costh_us_Oth_us^(1-epsilon)*broad_share_us(1,6));

lowshare_us_Fin_us=(psi_l^epsilon*w_us_L^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,7)+psi_h^epsilon*costh_us_Fin_us^(1-epsilon)*broad_share_us(1,8));
highshare_us_Fin_us=(psi_h^epsilon*costh_us_Fin_us^(1-epsilon))/(psi_l^epsilon*w_us_L^(1-epsilon)*broad_share_us(1,7)+psi_h^epsilon*costh_us_Fin_us^(1-epsilon)*broad_share_us(1,8));

%Europe

lowshare_eu_IT_eu=(psi_l^epsilon*w_eu_L^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,1)+psi_h^epsilon*costh_eu_IT_eu^(1-epsilon)*broad_share_eu(1,2));
highshare_eu_IT_eu=(psi_h^epsilon*costh_eu_IT_eu^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,1)+psi_h^epsilon*costh_eu_IT_eu^(1-epsilon)*broad_share_eu(1,2));

lowshare_eu_Man_eu=(psi_l^epsilon*w_eu_L^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,3)+psi_h^epsilon*costh_eu_Man_eu^(1-epsilon)*broad_share_eu(1,4));
highshare_eu_Man_eu=(psi_h^epsilon*costh_eu_Man_eu^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,3)+psi_h^epsilon*costh_eu_Man_eu^(1-epsilon)*broad_share_eu(1,4));

lowshare_eu_Oth_eu=(psi_l^epsilon*w_eu_L^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,5)+psi_h^epsilon*costh_eu_Oth_eu^(1-epsilon)*broad_share_eu(1,6));
highshare_eu_Oth_eu=(psi_h^epsilon*costh_eu_Oth_eu^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,5)+psi_h^epsilon*costh_eu_Oth_eu^(1-epsilon)*broad_share_eu(1,6));


lowshare_eu_Fin_eu=(psi_l^epsilon*w_eu_L^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,7)+psi_h^epsilon*costh_eu_Fin_eu^(1-epsilon)*broad_share_eu(1,8));
highshare_eu_Fin_eu=(psi_h^epsilon*costh_eu_Fin_eu^(1-epsilon))/(psi_l^epsilon*w_eu_L^(1-epsilon)*broad_share_eu(1,7)+psi_h^epsilon*costh_eu_Fin_eu^(1-epsilon)*broad_share_eu(1,8));





%Canada


lowshare_ca_IT_ca=(psi_l^epsilon*w_ca_L^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,1)+psi_h^epsilon*costh_ca_IT_ca^(1-epsilon)*broad_share_ca(1,2));
highshare_ca_IT_ca=(psi_h^epsilon*costh_ca_IT_ca^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,1)+psi_h^epsilon*costh_ca_IT_ca^(1-epsilon)*broad_share_ca(1,2));

lowshare_ca_Man_ca=(psi_l^epsilon*w_ca_L^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,3)+psi_h^epsilon*costh_ca_Man_ca^(1-epsilon)*broad_share_ca(1,4));
highshare_ca_Man_ca=(psi_h^epsilon*costh_ca_Man_ca^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,3)+psi_h^epsilon*costh_ca_Man_ca^(1-epsilon)*broad_share_ca(1,4));

lowshare_ca_Oth_ca=(psi_l^epsilon*w_ca_L^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,5)+psi_h^epsilon*costh_ca_Oth_ca^(1-epsilon)*broad_share_ca(1,6));
highshare_ca_Oth_ca=(psi_h^epsilon*costh_ca_Oth_ca^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,5)+psi_h^epsilon*costh_ca_Oth_ca^(1-epsilon)*broad_share_ca(1,6));

lowshare_ca_Fin_ca=(psi_l^epsilon*w_ca_L^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,7)+psi_h^epsilon*costh_ca_Fin_ca^(1-epsilon)*broad_share_ca(1,8));
highshare_ca_Fin_ca=(psi_h^epsilon*costh_ca_Fin_ca^(1-epsilon))/(psi_l^epsilon*w_ca_L^(1-epsilon)*broad_share_ca(1,7)+psi_h^epsilon*costh_ca_Fin_ca^(1-epsilon)*broad_share_ca(1,8));


%India

lowshare_in_IT_in=(psi_l^epsilon*w_in_L^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,1)+psi_h^epsilon*cost_in_IT_in^(1-epsilon)*broad_share_in(1,2));
highshare_in_IT_in=(psi_h^epsilon*cost_in_IT_in^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,1)+psi_h^epsilon*cost_in_IT_in^(1-epsilon)*broad_share_in(1,2));

lowshare_in_Man_in=(psi_l^epsilon*w_in_L^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,3)+psi_h^epsilon*cost_in_Man_in^(1-epsilon)*broad_share_in(1,4));
highshare_in_Man_in=(psi_h^epsilon*cost_in_Man_in^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,3)+psi_h^epsilon*cost_in_Man_in^(1-epsilon)*broad_share_in(1,4));

lowshare_in_Oth_in=(psi_l^epsilon*w_in_L^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,5)+psi_h^epsilon*cost_in_Oth_in^(1-epsilon)*broad_share_in(1,6));
highshare_in_Oth_in=(psi_h^epsilon*cost_in_Oth_in^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,5)+psi_h^epsilon*cost_in_Oth_in^(1-epsilon)*broad_share_in(1,6));

lowshare_in_Fin_in=(psi_l^epsilon*w_in_L^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,7)+psi_h^epsilon*cost_in_Fin_in^(1-epsilon)*broad_share_in(1,8));
highshare_in_Fin_in=(psi_h^epsilon*cost_in_Fin_in^(1-epsilon))/(psi_l^epsilon*w_in_L^(1-epsilon)*broad_share_in(1,7)+psi_h^epsilon*cost_in_Fin_in^(1-epsilon)*broad_share_in(1,8));




%China


lowshare_ch_IT_ch=(psi_l^epsilon*w_ch_L^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,1)+psi_h^epsilon*cost_ch_IT_ch^(1-epsilon)*broad_share_ch(1,2));
highshare_ch_IT_ch=(psi_h^epsilon*cost_ch_IT_ch^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,1)+psi_h^epsilon*cost_ch_IT_ch^(1-epsilon)*broad_share_ch(1,2));

lowshare_ch_Man_ch=(psi_l^epsilon*w_ch_L^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,3)+psi_h^epsilon*cost_ch_Man_ch^(1-epsilon)*broad_share_ch(1,4));
highshare_ch_Man_ch=(psi_h^epsilon*cost_ch_Man_ch^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,3)+psi_h^epsilon*cost_ch_Man_ch^(1-epsilon)*broad_share_ch(1,4));

lowshare_ch_Oth_ch=(psi_l^epsilon*w_ch_L^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,5)+psi_h^epsilon*cost_ch_Oth_ch^(1-epsilon)*broad_share_ch(1,6));
highshare_ch_Oth_ch=(psi_h^epsilon*cost_ch_Oth_ch^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,5)+psi_h^epsilon*cost_ch_Oth_ch^(1-epsilon)*broad_share_ch(1,6));

lowshare_ch_Fin_ch=(psi_l^epsilon*w_ch_L^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,7)+psi_h^epsilon*cost_ch_Fin_ch^(1-epsilon)*broad_share_ch(1,8));
highshare_ch_Fin_ch=(psi_h^epsilon*cost_ch_Fin_ch^(1-epsilon))/(psi_l^epsilon*w_ch_L^(1-epsilon)*broad_share_ch(1,7)+psi_h^epsilon*cost_ch_Fin_ch^(1-epsilon)*broad_share_ch(1,8));



%Other

lowshare_ot_IT_ot=(psi_l^epsilon*w_ot_L^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,1)+psi_h^epsilon*cost_ot_IT_ot^(1-epsilon)*broad_share_ot(1,2));
highshare_ot_IT_ot=(psi_h^epsilon*cost_ot_IT_ot^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,1)+psi_h^epsilon*cost_ot_IT_ot^(1-epsilon)*broad_share_ot(1,2));

lowshare_ot_Man_ot=(psi_l^epsilon*w_ot_L^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,3)+psi_h^epsilon*cost_ot_Man_ot^(1-epsilon)*broad_share_ot(1,4));
highshare_ot_Man_ot=(psi_h^epsilon*cost_ot_Man_ot^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,3)+psi_h^epsilon*cost_ot_Man_ot^(1-epsilon)*broad_share_ot(1,4));

lowshare_ot_Oth_ot=(psi_l^epsilon*w_ot_L^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,5)+psi_h^epsilon*cost_ot_Oth_ot^(1-epsilon)*broad_share_ot(1,6));
highshare_ot_Oth_ot=(psi_h^epsilon*cost_ot_Oth_ot^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,5)+psi_h^epsilon*cost_ot_Oth_ot^(1-epsilon)*broad_share_ot(1,6));

lowshare_ot_Fin_ot=(psi_l^epsilon*w_ot_L^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,7)+psi_h^epsilon*cost_ot_Fin_ot^(1-epsilon)*broad_share_ot(1,8));
highshare_ot_Fin_ot=(psi_h^epsilon*cost_ot_Fin_ot^(1-epsilon))/(psi_l^epsilon*w_ot_L^(1-epsilon)*broad_share_ot(1,7)+psi_h^epsilon*cost_ot_Fin_ot^(1-epsilon)*broad_share_ot(1,8));


%High-skill share

%US

hshare_us_IT_us_d=(psi_d^lambda*w_us_IT_us_d^(1-lambda))/(psi_d^lambda*w_us_IT_us_d^(1-lambda)*skill_shares_us_us(1,1)+psi_f^lambda*w_us_IT_us_f^(1-lambda)*skill_shares_us_us(1,2));
hshare_us_IT_us_f=(psi_f^lambda*w_us_IT_us_f^(1-lambda))/(psi_d^lambda*w_us_IT_us_d^(1-lambda)*skill_shares_us_us(1,1)+psi_f^lambda*w_us_IT_us_f^(1-lambda)*skill_shares_us_us(1,2));


hshare_us_Man_us_d=psi_d^lambda*w_us_Man_us_d^(1-lambda)/(psi_d^lambda*w_us_Man_us_d^(1-lambda)*skill_shares_us_us(1,3)+psi_f^lambda*w_us_Man_us_f^(1-lambda)*skill_shares_us_us(1,4));
hshare_us_Man_us_f=psi_f^lambda*w_us_Man_us_f^(1-lambda)/(psi_d^lambda*w_us_Man_us_d^(1-lambda)*skill_shares_us_us(1,3)+psi_f^lambda*w_us_Man_us_f^(1-lambda)*skill_shares_us_us(1,4));


hshare_us_Oth_us_d=(psi_d^lambda*w_us_Oth_us_d^(1-lambda))/(psi_d^lambda*w_us_Oth_us_d^(1-lambda)*skill_shares_us_us(1,5)+psi_f^lambda*w_us_Oth_us_f^(1-lambda)*skill_shares_us_us(1,6));
hshare_us_Oth_us_f=(psi_f^lambda*w_us_Oth_us_f^(1-lambda))/(psi_d^lambda*w_us_Oth_us_d^(1-lambda)*skill_shares_us_us(1,5)+psi_f^lambda*w_us_Oth_us_f^(1-lambda)*skill_shares_us_us(1,6));


hshare_us_Fin_us_d=psi_d^lambda*w_us_Fin_us_d^(1-lambda)/(psi_d^lambda*w_us_Fin_us_d^(1-lambda)*skill_shares_us_us(1,7)+psi_f^lambda*w_us_Fin_us_f^(1-lambda)*skill_shares_us_us(1,8));
hshare_us_Fin_us_f=psi_f^lambda*w_us_Fin_us_f^(1-lambda)/(psi_d^lambda*w_us_Fin_us_d^(1-lambda)*skill_shares_us_us(1,7)+psi_f^lambda*w_us_Fin_us_f^(1-lambda)*skill_shares_us_us(1,8));



%Europe

hshare_eu_IT_eu_d=psi_d^lambda*w_eu_IT_eu_d^(1-lambda)/(psi_d^lambda*w_eu_IT_eu_d^(1-lambda)*skill_shares_eu_eu(1,1)+psi_f^lambda*w_eu_IT_eu_f^(1-lambda)*skill_shares_eu_eu(1,2));
hshare_eu_IT_eu_f=psi_f^lambda*w_eu_IT_eu_f^(1-lambda)/(psi_d^lambda*w_eu_IT_eu_d^(1-lambda)*skill_shares_eu_eu(1,1)+psi_f^lambda*w_eu_IT_eu_f^(1-lambda)*skill_shares_eu_eu(1,2));

hshare_eu_Man_eu_d=psi_d^lambda*w_eu_Man_eu_d^(1-lambda)/(psi_d^lambda*w_eu_Man_eu_d^(1-lambda)*skill_shares_eu_eu(1,3)+psi_f^lambda*w_eu_Man_eu_f^(1-lambda)*skill_shares_eu_eu(1,4));
hshare_eu_Man_eu_f=psi_f^lambda*w_eu_Man_eu_f^(1-lambda)/(psi_d^lambda*w_eu_Man_eu_d^(1-lambda)*skill_shares_eu_eu(1,3)+psi_f^lambda*w_eu_Man_eu_f^(1-lambda)*skill_shares_eu_eu(1,4));

hshare_eu_Oth_eu_d=psi_d^lambda*w_eu_Oth_eu_d^(1-lambda)/(psi_d^lambda*w_eu_Oth_eu_d^(1-lambda)*skill_shares_eu_eu(1,5)+psi_f^lambda*w_eu_Oth_eu_f^(1-lambda)*skill_shares_eu_eu(1,6));
hshare_eu_Oth_eu_f=psi_f^lambda*w_eu_Oth_eu_f^(1-lambda)/(psi_d^lambda*w_eu_Oth_eu_d^(1-lambda)*skill_shares_eu_eu(1,5)+psi_f^lambda*w_eu_Oth_eu_f^(1-lambda)*skill_shares_eu_eu(1,6));

hshare_eu_Fin_eu_d=psi_d^lambda*w_eu_Fin_eu_d^(1-lambda)/(psi_d^lambda*w_eu_Fin_eu_d^(1-lambda)*skill_shares_eu_eu(1,7)+psi_f^lambda*w_eu_Fin_eu_f^(1-lambda)*skill_shares_eu_eu(1,8));
hshare_eu_Fin_eu_f=psi_f^lambda*w_eu_Fin_eu_f^(1-lambda)/(psi_d^lambda*w_eu_Fin_eu_d^(1-lambda)*skill_shares_eu_eu(1,7)+psi_f^lambda*w_eu_Fin_eu_f^(1-lambda)*skill_shares_eu_eu(1,8));




%Canada

hshare_ca_IT_ca_d=psi_d^lambda*w_ca_IT_ca_d^(1-lambda)/(psi_d^lambda*w_ca_IT_ca_d^(1-lambda)*skill_shares_ca_ca(1,1)+psi_f^lambda*w_ca_IT_ca_f^(1-lambda)*skill_shares_ca_ca(1,2));
hshare_ca_IT_ca_f=psi_f^lambda*w_ca_IT_ca_f^(1-lambda)/(psi_d^lambda*w_ca_IT_ca_d^(1-lambda)*skill_shares_ca_ca(1,1)+psi_f^lambda*w_ca_IT_ca_f^(1-lambda)*skill_shares_ca_ca(1,2));

hshare_ca_Man_ca_d=psi_d^lambda*w_ca_Man_ca_d^(1-lambda)/(psi_d^lambda*w_ca_Man_ca_d^(1-lambda)*skill_shares_ca_ca(1,3)+psi_f^lambda*w_ca_Man_ca_f^(1-lambda)*skill_shares_ca_ca(1,4));
hshare_ca_Man_ca_f=psi_f^lambda*w_ca_Man_ca_f^(1-lambda)/(psi_d^lambda*w_ca_Man_ca_d^(1-lambda)*skill_shares_ca_ca(1,3)+psi_f^lambda*w_ca_Man_ca_f^(1-lambda)*skill_shares_ca_ca(1,4));

hshare_ca_Oth_ca_d=psi_d^lambda*w_ca_Oth_ca_d^(1-lambda)/(psi_d^lambda*w_ca_Oth_ca_d^(1-lambda)*skill_shares_ca_ca(1,5)+psi_f^lambda*w_ca_Oth_ca_f^(1-lambda)*skill_shares_ca_ca(1,6));
hshare_ca_Oth_ca_f=psi_f^lambda*w_ca_Oth_ca_f^(1-lambda)/(psi_d^lambda*w_ca_Oth_ca_d^(1-lambda)*skill_shares_ca_ca(1,5)+psi_f^lambda*w_ca_Oth_ca_f^(1-lambda)*skill_shares_ca_ca(1,6));


hshare_ca_Fin_ca_d=psi_d^lambda*w_ca_Fin_ca_d^(1-lambda)/(psi_d^lambda*w_ca_Fin_ca_d^(1-lambda)*skill_shares_ca_ca(1,7)+psi_f^lambda*w_ca_Fin_ca_f^(1-lambda)*skill_shares_ca_ca(1,8));
hshare_ca_Fin_ca_f=psi_f^lambda*w_ca_Fin_ca_f^(1-lambda)/(psi_d^lambda*w_ca_Fin_ca_d^(1-lambda)*skill_shares_ca_ca(1,7)+psi_f^lambda*w_ca_Fin_ca_f^(1-lambda)*skill_shares_ca_ca(1,8));



%High-skill Labor supply

%US

h_us_IT_us_d=mig_us_IT_us_us^((kappa-1)/kappa)*N_us*A_us_IT^(1/kappa);
h_us_IT_us_f=mig_in_IT_us_us^((kappa-1)/kappa)*N_in*A_in_IT^(1/kappa)*Foreign_IT_us_us(1,1)+mig_eu_IT_us_us^((kappa-1)/kappa)*N_eu*A_eu_IT^(1/kappa)*Foreign_IT_us_us(1,2)+...
    mig_ca_IT_us_us^((kappa-1)/kappa)*N_ca*A_ca_IT^(1/kappa)*Foreign_IT_us_us(1,3)+mig_ch_IT_us_us^((kappa-1)/kappa)*N_ch*A_ch_IT^(1/kappa)*Foreign_IT_us_us(1,4)+...
    mig_ot_IT_us_us^((kappa-1)/kappa)*N_ot*A_ot_IT^(1/kappa)*Foreign_IT_us_us(1,5);



h_us_Man_us_d=mig_us_Man_us_us^((kappa-1)/kappa)*N_us*A_us_Man^(1/kappa);
h_us_Man_us_f=mig_in_Man_us_us^((kappa-1)/kappa)*N_in*A_in_Man^(1/kappa)*Foreign_Man_us_us(1,1)+mig_eu_Man_us_us^((kappa-1)/kappa)*N_eu*A_eu_Man^(1/kappa)*Foreign_Man_us_us(1,2)+...
    mig_ca_Man_us_us^((kappa-1)/kappa)*N_ca*A_ca_Man^(1/kappa)*Foreign_Man_us_us(1,3)+mig_ch_Man_us_us^((kappa-1)/kappa)*N_ch*A_ch_Man^(1/kappa)*Foreign_Man_us_us(1,4)+...
    mig_ot_Man_us_us^((kappa-1)/kappa)*N_ot*A_ot_Man^(1/kappa)*Foreign_Man_us_us(1,5);


h_us_Oth_us_d=mig_us_Oth_us_us^((kappa-1)/kappa)*N_us*A_us_Oth^(1/kappa);
h_us_Oth_us_f=mig_in_Oth_us_us^((kappa-1)/kappa)*N_in*A_in_Oth^(1/kappa)*Foreign_Oth_us_us(1,1)+mig_eu_Oth_us_us^((kappa-1)/kappa)*N_eu*A_eu_Oth^(1/kappa)*Foreign_Oth_us_us(1,2)+...
    mig_ca_Oth_us_us^((kappa-1)/kappa)*N_ca*A_ca_Oth^(1/kappa)*Foreign_Oth_us_us(1,3)+mig_ch_Oth_us_us^((kappa-1)/kappa)*N_ch*A_ch_Oth^(1/kappa)*Foreign_Oth_us_us(1,4)+...
    mig_ot_Oth_us_us^((kappa-1)/kappa)*N_ot*A_ot_Oth^(1/kappa)*Foreign_Oth_us_us(1,5);


h_us_Fin_us_d=mig_us_Fin_us_us^((kappa-1)/kappa)*N_us*A_us_Fin^(1/kappa);
h_us_Fin_us_f=mig_in_Fin_us_us^((kappa-1)/kappa)*N_in*A_in_Fin^(1/kappa)*Foreign_Fin_us_us(1,1)+mig_eu_Fin_us_us^((kappa-1)/kappa)*N_eu*A_eu_Fin^(1/kappa)*Foreign_Fin_us_us(1,2)+...
    mig_ca_Fin_us_us^((kappa-1)/kappa)*N_ca*A_ca_Fin^(1/kappa)*Foreign_Fin_us_us(1,3)+mig_ch_Fin_us_us^((kappa-1)/kappa)*N_ch*A_ch_Fin^(1/kappa)*Foreign_Fin_us_us(1,4)+...
    mig_ot_Fin_us_us^((kappa-1)/kappa)*N_ot*A_ot_Fin^(1/kappa)*Foreign_Fin_us_us(1,5);


%Europe

h_eu_IT_eu_d=mig_eu_IT_eu_eu^((kappa-1)/kappa)*N_eu*A_eu_IT^(1/kappa);
h_eu_IT_eu_f=mig_in_IT_eu_eu^((kappa-1)/kappa)*N_in*A_in_IT^(1/kappa)*Foreign_IT_eu_eu(1,1)+mig_us_IT_eu_eu^((kappa-1)/kappa)*N_us*A_us_IT^(1/kappa)*Foreign_IT_eu_eu(1,2)+...
    mig_ca_IT_eu_eu^((kappa-1)/kappa)*N_ca*A_ca_IT^(1/kappa)*Foreign_IT_eu_eu(1,3)+mig_ch_IT_eu_eu^((kappa-1)/kappa)*N_ch*A_ch_IT^(1/kappa)*Foreign_IT_eu_eu(1,4)+...
    mig_ot_IT_eu_eu^((kappa-1)/kappa)*N_ot*A_ot_IT^(1/kappa)*Foreign_IT_eu_eu(1,5);


h_eu_Man_eu_d=mig_eu_Man_eu_eu^((kappa-1)/kappa)*N_eu*A_eu_Man^(1/kappa);
h_eu_Man_eu_f=mig_in_Man_eu_eu^((kappa-1)/kappa)*N_in*A_in_Man^(1/kappa)*Foreign_Man_eu_eu(1,1)+mig_us_Man_eu_eu^((kappa-1)/kappa)*N_us*A_us_Man^(1/kappa)*Foreign_Man_eu_eu(1,2)+...
    mig_ca_Man_eu_eu^((kappa-1)/kappa)*N_ca*A_ca_Man^(1/kappa)*Foreign_Man_eu_eu(1,3)+mig_ch_Man_eu_eu^((kappa-1)/kappa)*N_ch*A_ch_Man^(1/kappa)*Foreign_Man_eu_eu(1,4)+...
    mig_ot_Man_eu_eu^((kappa-1)/kappa)*N_ot*A_ot_Man^(1/kappa)*Foreign_Man_eu_eu(1,5);

h_eu_Oth_eu_d=mig_eu_Oth_eu_eu^((kappa-1)/kappa)*N_eu*A_eu_Oth^(1/kappa);
h_eu_Oth_eu_f=mig_in_Oth_eu_eu^((kappa-1)/kappa)*N_in*A_in_Oth^(1/kappa)*Foreign_Oth_eu_eu(1,1)+mig_us_Oth_eu_eu^((kappa-1)/kappa)*N_us*A_us_Oth^(1/kappa)*Foreign_Oth_eu_eu(1,2)+...
    mig_ca_Oth_eu_eu^((kappa-1)/kappa)*N_ca*A_ca_Oth^(1/kappa)*Foreign_Oth_eu_eu(1,3)+mig_ch_Oth_eu_eu^((kappa-1)/kappa)*N_ch*A_ch_Oth^(1/kappa)*Foreign_Oth_eu_eu(1,4)+...
    mig_ot_Oth_eu_eu^((kappa-1)/kappa)*N_ot*A_ot_Oth^(1/kappa)*Foreign_Oth_eu_eu(1,5);

h_eu_Fin_eu_d=mig_eu_Fin_eu_eu^((kappa-1)/kappa)*N_eu*A_eu_Fin^(1/kappa);
h_eu_Fin_eu_f=mig_in_Fin_eu_eu^((kappa-1)/kappa)*N_in*A_in_Fin^(1/kappa)*Foreign_Fin_eu_eu(1,1)+mig_us_Fin_eu_eu^((kappa-1)/kappa)*N_us*A_us_Fin^(1/kappa)*Foreign_Fin_eu_eu(1,2)+...
    mig_ca_Fin_eu_eu^((kappa-1)/kappa)*N_ca*A_ca_Fin^(1/kappa)*Foreign_Fin_eu_eu(1,3)+mig_ch_Fin_eu_eu^((kappa-1)/kappa)*N_ch*A_ch_Fin^(1/kappa)*Foreign_Fin_eu_eu(1,4)+...
    mig_ot_Fin_eu_eu^((kappa-1)/kappa)*N_ot*A_ot_Fin^(1/kappa)*Foreign_Fin_eu_eu(1,5);


%Canada

h_ca_IT_ca_d=mig_ca_IT_ca_ca^((kappa-1)/kappa)*N_ca*A_ca_IT^(1/kappa);
h_ca_IT_ca_f=mig_in_IT_ca_ca^((kappa-1)/kappa)*N_in*A_in_IT^(1/kappa)*Foreign_IT_ca_ca(1,1)+mig_eu_IT_ca_ca^((kappa-1)/kappa)*N_eu*A_eu_IT^(1/kappa)*Foreign_IT_ca_ca(1,2)+...
    mig_us_IT_ca_ca^((kappa-1)/kappa)*N_us*A_us_IT^(1/kappa)*Foreign_IT_ca_ca(1,3)+mig_ch_IT_ca_ca^((kappa-1)/kappa)*N_ch*A_ch_IT^(1/kappa)*Foreign_IT_ca_ca(1,4)+...
    mig_ot_IT_ca_ca^((kappa-1)/kappa)*N_ot*A_ot_IT^(1/kappa)*Foreign_IT_ca_ca(1,5);

h_ca_Man_ca_d=mig_ca_Man_ca_ca^((kappa-1)/kappa)*N_ca*A_ca_Man^(1/kappa);
h_ca_Man_ca_f=mig_in_Man_ca_ca^((kappa-1)/kappa)*N_in*A_in_Man^(1/kappa)*Foreign_Man_ca_ca(1,1)+mig_eu_Man_ca_ca^((kappa-1)/kappa)*N_eu*A_eu_Man^(1/kappa)*Foreign_Man_ca_ca(1,2)+...
    mig_us_Man_ca_ca^((kappa-1)/kappa)*N_us*A_us_Man^(1/kappa)*Foreign_Man_ca_ca(1,3)+mig_ch_Man_ca_ca^((kappa-1)/kappa)*N_ch*A_ch_Man^(1/kappa)*Foreign_Man_ca_ca(1,4)+...
    mig_ot_Man_ca_ca^((kappa-1)/kappa)*N_ot*A_ot_Man^(1/kappa)*Foreign_Man_ca_ca(1,5);

h_ca_Oth_ca_d=mig_ca_Oth_ca_ca^((kappa-1)/kappa)*N_ca*A_ca_Oth^(1/kappa);
h_ca_Oth_ca_f=mig_in_Oth_ca_ca^((kappa-1)/kappa)*N_in*A_in_Oth^(1/kappa)*Foreign_Oth_ca_ca(1,1)+mig_eu_Oth_ca_ca^((kappa-1)/kappa)*N_eu*A_eu_Oth^(1/kappa)*Foreign_Oth_ca_ca(1,2)+...
    mig_us_Oth_ca_ca^((kappa-1)/kappa)*N_us*A_us_Oth^(1/kappa)*Foreign_Oth_ca_ca(1,3)+mig_ch_Oth_ca_ca^((kappa-1)/kappa)*N_ch*A_ch_Oth^(1/kappa)*Foreign_Oth_ca_ca(1,4)+...
    mig_ot_Oth_ca_ca^((kappa-1)/kappa)*N_ot*A_ot_Oth^(1/kappa)*Foreign_Oth_ca_ca(1,5);

h_ca_Fin_ca_d=mig_ca_Fin_ca_ca^((kappa-1)/kappa)*N_ca*A_ca_Fin^(1/kappa);
h_ca_Fin_ca_f=mig_in_Fin_ca_ca^((kappa-1)/kappa)*N_in*A_in_Fin^(1/kappa)*Foreign_Fin_ca_ca(1,1)+mig_eu_Fin_ca_ca^((kappa-1)/kappa)*N_eu*A_eu_Fin^(1/kappa)*Foreign_Fin_ca_ca(1,2)+...
    mig_us_Fin_ca_ca^((kappa-1)/kappa)*N_us*A_us_Fin^(1/kappa)*Foreign_Fin_ca_ca(1,3)+mig_ch_Fin_ca_ca^((kappa-1)/kappa)*N_ch*A_ch_Fin^(1/kappa)*Foreign_Fin_ca_ca(1,4)+...
    mig_ot_Fin_ca_ca^((kappa-1)/kappa)*N_ot*A_ot_Fin^(1/kappa)*Foreign_Fin_ca_ca(1,5);


%India

h_in_IT_in=mig_in_IT_in_in^((kappa-1)/kappa)*N_in*A_in_IT^(1/kappa);
h_in_Man_in=mig_in_Man_in_in^((kappa-1)/kappa)*N_in*A_in_Man^(1/kappa);
h_in_Oth_in=mig_in_Oth_in_in^((kappa-1)/kappa)*N_in*A_in_Oth^(1/kappa);
h_in_Fin_in=mig_in_Fin_in_in^((kappa-1)/kappa)*N_in*A_in_Fin^(1/kappa);

%China


h_ch_IT_ch=mig_ch_IT_ch_ch^((kappa-1)/kappa)*N_ch*A_ch_IT^(1/kappa);
h_ch_Man_ch=mig_ch_Man_ch_ch^((kappa-1)/kappa)*N_ch*A_ch_Man^(1/kappa);
h_ch_Oth_ch=mig_ch_Oth_ch_ch^((kappa-1)/kappa)*N_ch*A_ch_Oth^(1/kappa);
h_ch_Fin_ch=mig_ch_Fin_ch_ch^((kappa-1)/kappa)*N_ch*A_ch_Fin^(1/kappa);


%Other

h_ot_IT_ot=mig_ot_IT_ot_ot^((kappa-1)/kappa)*N_ot*A_ot_IT^(1/kappa);
h_ot_Man_ot=mig_ot_Man_ot_ot^((kappa-1)/kappa)*N_ot*A_ot_Man^(1/kappa);
h_ot_Oth_ot=mig_ot_Oth_ot_ot^((kappa-1)/kappa)*N_ot*A_ot_Oth^(1/kappa);
h_ot_Fin_ot=mig_ot_Fin_ot_ot^((kappa-1)/kappa)*N_ot*A_ot_Fin^(1/kappa);




%Technology by location-industry

Ttil_us_IT=T_us_IT*(cost_us_IT_us)^(-theta)*MNE_shares_IT_us(1,1);
Ttil_us_Man=T_us_Man*(cost_us_Man_us)^(-theta)*MNE_shares_Man_us(1,1);
Ttil_us_Oth=T_us_Oth*(cost_us_Oth_us)^(-theta);
Ttil_us_Fin=T_us_Fin*(cost_us_Fin_us)^(-theta)*MNE_shares_Fin_us(1,1);

Ttil_in_IT=T_in_IT*(cost_in_IT_in)^(-theta)*MNE_shares_IT_in(1,2);
Ttil_in_Man=T_in_Man*(cost_in_Man_in)^(-theta)*MNE_shares_Man_in(1,2);
Ttil_in_Oth=T_in_Oth*(cost_in_Oth_in)^(-theta);
Ttil_in_Fin=T_in_Fin*(cost_in_Fin_in)^(-theta)*MNE_shares_Fin_in(1,2);

Ttil_eu_IT=T_eu_IT*(cost_eu_IT_eu)^(-theta)*MNE_shares_IT_eu(1,3);
Ttil_eu_Man=T_eu_Man*(cost_eu_Man_eu)^(-theta)*MNE_shares_Man_eu(1,3);
Ttil_eu_Oth=T_eu_Oth*(cost_eu_Oth_eu)^(-theta);
Ttil_eu_Fin=T_eu_Fin*(cost_eu_Fin_eu)^(-theta)*MNE_shares_Fin_eu(1,3);


Ttil_ca_IT=T_ca_IT*(cost_ca_IT_ca)^(-theta)*MNE_shares_IT_ca(1,4);
Ttil_ca_Man=T_ca_Man*(cost_ca_Man_ca)^(-theta)*MNE_shares_Man_ca(1,4);
Ttil_ca_Oth=T_ca_Oth*(cost_ca_Oth_ca)^(-theta);
Ttil_ca_Fin=T_ca_Fin*(cost_ca_Fin_ca)^(-theta)*MNE_shares_Fin_ca(1,4);

Ttil_ch_IT=T_ch_IT*(cost_ch_IT_ch)^(-theta)*MNE_shares_IT_ch(1,5);
Ttil_ch_Man=T_ch_Man*(cost_ch_Man_ch)^(-theta)*MNE_shares_Man_ch(1,5);
Ttil_ch_Oth=T_ch_Oth*(cost_ch_Oth_ch)^(-theta);
Ttil_ch_Fin=T_ch_Fin*(cost_ch_Fin_ch)^(-theta)*MNE_shares_Fin_ch(1,5);


Ttil_ot_IT=T_ot_IT*(cost_ot_IT_ot)^(-theta);
Ttil_ot_Man=T_ot_Man*(cost_ot_Man_ot)^(-theta);
Ttil_ot_Oth=T_ot_Oth*(cost_ot_Oth_ot)^(-theta);
Ttil_ot_Fin=T_ot_Fin*(cost_ot_Fin_ot)^(-theta);



%Prices

p_us_IT=(Ttil_us_IT*Trade_shares_IT_us(1,1)+tau_us_in_IT^(-theta)*Ttil_in_IT*Trade_shares_IT_us(1,2)+tau_us_eu_IT^(-theta)*Ttil_eu_IT*Trade_shares_IT_us(1,3)+...
    tau_us_ca_IT^(-theta)*Ttil_ca_IT*Trade_shares_IT_us(1,4)+tau_us_ch_IT^(-theta)*Ttil_ch_IT*Trade_shares_IT_us(1,5)+tau_us_ot_IT^(-theta)*Ttil_ot_IT*Trade_shares_IT_us(1,6))^(-1/theta);
p_us_Man=(Ttil_us_Man*Trade_shares_Man_us(1,1)+tau_us_in_Man^(-theta)*Ttil_in_Man*Trade_shares_Man_us(1,2)+tau_us_eu_Man^(-theta)*Ttil_eu_Man*Trade_shares_Man_us(1,3)+...
    tau_us_ca_Man^(-theta)*Ttil_ca_Man*Trade_shares_Man_us(1,4)+tau_us_ch_Man^(-theta)*Ttil_ch_Man*Trade_shares_Man_us(1,5)+tau_us_ot_Man^(-theta)*Ttil_ot_Man*Trade_shares_Man_us(1,6))^(-1/theta);
p_us_Oth=(Ttil_us_Oth*Trade_shares_Oth_us(1,1)+tau_us_in_Oth^(-theta)*Ttil_in_Oth*Trade_shares_Oth_us(1,2)+tau_us_eu_Oth^(-theta)*Ttil_eu_Oth*Trade_shares_Oth_us(1,3)+...
    tau_us_ca_Oth^(-theta)*Ttil_ca_Oth*Trade_shares_Oth_us(1,4)+tau_us_ch_Oth^(-theta)*Ttil_ch_Oth*Trade_shares_Oth_us(1,5)+tau_us_ot_Oth^(-theta)*Ttil_ot_Oth*Trade_shares_Oth_us(1,6))^(-1/theta);
p_us_Fin=(Ttil_us_Fin*Trade_shares_Fin_us(1,1)+tau_us_in_Fin^(-theta)*Ttil_in_Fin*Trade_shares_Fin_us(1,2)+tau_us_eu_Fin^(-theta)*Ttil_eu_Fin*Trade_shares_Fin_us(1,3)+...
    tau_us_ca_Fin^(-theta)*Ttil_ca_Fin*Trade_shares_Fin_us(1,4)+tau_us_ch_Fin^(-theta)*Ttil_ch_Fin*Trade_shares_Fin_us(1,5)+tau_us_ot_Fin^(-theta)*Ttil_ot_Fin*Trade_shares_Fin_us(1,6))^(-1/theta);

p_in_IT=(tau_in_us_IT^(-theta)*Ttil_us_IT*Trade_shares_IT_in(1,1)+Ttil_in_IT*Trade_shares_IT_in(1,2)+tau_in_eu_IT^(-theta)*Ttil_eu_IT*Trade_shares_IT_in(1,3)+...
    tau_in_ca_IT^(-theta)*Ttil_ca_IT*Trade_shares_IT_in(1,4)+tau_in_ch_IT^(-theta)*Ttil_ch_IT*Trade_shares_IT_in(1,5)+tau_in_ot_IT^(-theta)*Ttil_ot_IT*Trade_shares_IT_in(1,6))^(-1/theta);
p_in_Man=(tau_in_us_Man^(-theta)*Ttil_us_Man*Trade_shares_Man_in(1,1)+Ttil_in_Man*Trade_shares_Man_in(1,2)+tau_in_eu_Man^(-theta)*Ttil_eu_Man*Trade_shares_Man_in(1,3)+...
    tau_in_ca_Man^(-theta)*Ttil_ca_Man*Trade_shares_Man_in(1,4)+tau_in_ch_Man^(-theta)*Ttil_ch_Man*Trade_shares_Man_in(1,5)+tau_in_ot_Man^(-theta)*Ttil_ot_Man*Trade_shares_Man_in(1,6))^(-1/theta);
p_in_Oth=(tau_in_us_Oth^(-theta)*Ttil_us_Oth*Trade_shares_Oth_in(1,1)+Ttil_in_Oth*Trade_shares_Oth_in(1,2)+tau_in_eu_Oth^(-theta)*Ttil_eu_Oth*Trade_shares_Oth_in(1,3)+...
    tau_in_ca_Oth^(-theta)*Ttil_ca_Oth*Trade_shares_Oth_in(1,4)+tau_in_ch_Oth^(-theta)*Ttil_ch_Oth*Trade_shares_Oth_in(1,5)+tau_in_ot_Oth^(-theta)*Ttil_ot_Oth*Trade_shares_Oth_in(1,6))^(-1/theta);
p_in_Fin=(tau_in_us_Fin^(-theta)*Ttil_us_Fin*Trade_shares_Fin_in(1,1)+Ttil_in_Fin*Trade_shares_Fin_in(1,2)+tau_in_eu_Fin^(-theta)*Ttil_eu_Fin*Trade_shares_Fin_in(1,3)+...
    tau_in_ca_Fin^(-theta)*Ttil_ca_Fin*Trade_shares_Fin_in(1,4)+tau_in_ch_Fin^(-theta)*Ttil_ch_Fin*Trade_shares_Fin_in(1,5)+tau_in_ot_Fin^(-theta)*Ttil_ot_Fin*Trade_shares_Fin_in(1,6))^(-1/theta);

p_eu_IT=(tau_eu_us_IT^(-theta)*Ttil_us_IT*Trade_shares_IT_eu(1,1)+tau_eu_in_IT^(-theta)*Ttil_in_IT*Trade_shares_IT_eu(1,2)+Ttil_eu_IT*Trade_shares_IT_eu(1,3)+...
    tau_eu_ca_IT^(-theta)*Ttil_ca_IT*Trade_shares_IT_eu(1,4)+tau_eu_ch_IT^(-theta)*Ttil_ch_IT*Trade_shares_IT_eu(1,5)+tau_eu_ot_IT^(-theta)*Ttil_ot_IT*Trade_shares_IT_eu(1,6))^(-1/theta);
p_eu_Man=(tau_eu_us_Man^(-theta)*Ttil_us_Man*Trade_shares_Man_eu(1,1)+tau_eu_in_Man^(-theta)*Ttil_in_Man*Trade_shares_Man_eu(1,2)+Ttil_eu_Man*Trade_shares_Man_eu(1,3)+...
    tau_eu_ca_Man^(-theta)*Ttil_ca_Man*Trade_shares_Man_eu(1,4)+tau_eu_ch_Man^(-theta)*Ttil_ch_Man*Trade_shares_Man_eu(1,5)+tau_eu_ot_Man^(-theta)*Ttil_ot_Man*Trade_shares_Man_eu(1,6))^(-1/theta);
p_eu_Oth=(tau_eu_us_Oth^(-theta)*Ttil_us_Oth*Trade_shares_Oth_eu(1,1)+tau_eu_in_Oth^(-theta)*Ttil_in_Oth*Trade_shares_Oth_eu(1,2)+Ttil_eu_Oth*Trade_shares_Oth_eu(1,3)+...
    tau_eu_ca_Oth^(-theta)*Ttil_ca_Oth*Trade_shares_Oth_eu(1,4)+tau_eu_ch_Oth^(-theta)*Ttil_ch_Oth*Trade_shares_Oth_eu(1,5)+tau_eu_ot_Oth^(-theta)*Ttil_ot_Oth*Trade_shares_Oth_eu(1,6))^(-1/theta);
p_eu_Fin=(tau_eu_us_Fin^(-theta)*Ttil_us_Fin*Trade_shares_Fin_eu(1,1)+tau_eu_in_Fin^(-theta)*Ttil_in_Fin*Trade_shares_Fin_eu(1,2)+Ttil_eu_Fin*Trade_shares_Fin_eu(1,3)+...
    tau_eu_ca_Fin^(-theta)*Ttil_ca_Fin*Trade_shares_Fin_eu(1,4)+tau_eu_ch_Fin^(-theta)*Ttil_ch_Fin*Trade_shares_Fin_eu(1,5)+tau_eu_ot_Fin^(-theta)*Ttil_ot_Fin*Trade_shares_Fin_eu(1,6))^(-1/theta);

p_ca_IT=(tau_ca_us_IT^(-theta)*Ttil_us_IT*Trade_shares_IT_ca(1,1)+tau_ca_in_IT^(-theta)*Ttil_in_IT*Trade_shares_IT_ca(1,2)+tau_ca_eu_IT^(-theta)*Ttil_eu_IT*Trade_shares_IT_ca(1,3)+...
    Ttil_ca_IT*Trade_shares_IT_ca(1,4)+tau_ca_ch_IT^(-theta)*Ttil_ch_IT*Trade_shares_IT_ca(1,5)+tau_ca_ot_IT^(-theta)*Ttil_ot_IT*Trade_shares_IT_ca(1,6))^(-1/theta);
p_ca_Man=(tau_ca_us_Man^(-theta)*Ttil_us_Man*Trade_shares_Man_ca(1,1)+tau_ca_in_Man^(-theta)*Ttil_in_Man*Trade_shares_Man_ca(1,2)+tau_ca_eu_Man^(-theta)*Ttil_eu_Man*Trade_shares_Man_ca(1,3)+...
    Ttil_ca_Man*Trade_shares_Man_ca(1,4)+tau_ca_ch_Man^(-theta)*Ttil_ch_Man*Trade_shares_Man_ca(1,5)+tau_ca_ot_Man^(-theta)*Ttil_ot_Man*Trade_shares_Man_ca(1,6))^(-1/theta);
p_ca_Oth=(tau_ca_us_Oth^(-theta)*Ttil_us_Oth*Trade_shares_Oth_ca(1,1)+tau_ca_in_Oth^(-theta)*Ttil_in_Oth*Trade_shares_Oth_ca(1,2)+tau_ca_eu_Oth^(-theta)*Ttil_eu_Oth*Trade_shares_Oth_ca(1,3)+...
    Ttil_ca_Oth*Trade_shares_Oth_ca(1,4)+tau_ca_ch_Oth^(-theta)*Ttil_ch_Oth*Trade_shares_Oth_ca(1,5)+tau_ca_ot_Oth^(-theta)*Ttil_ot_Oth*Trade_shares_Oth_ca(1,6))^(-1/theta);
p_ca_Fin=(tau_ca_us_Fin^(-theta)*Ttil_us_Fin*Trade_shares_Fin_ca(1,1)+tau_ca_in_Fin^(-theta)*Ttil_in_Fin*Trade_shares_Fin_ca(1,2)+tau_ca_eu_Fin^(-theta)*Ttil_eu_Fin*Trade_shares_Fin_ca(1,3)+...
    Ttil_ca_Fin*Trade_shares_Fin_ca(1,4)+tau_ca_ch_Fin^(-theta)*Ttil_ch_Fin*Trade_shares_Fin_ca(1,5)+tau_ca_ot_Fin^(-theta)*Ttil_ot_Fin*Trade_shares_Fin_ca(1,6))^(-1/theta);

p_ch_IT=(tau_ch_us_IT^(-theta)*Ttil_us_IT*Trade_shares_IT_ch(1,1)+tau_ch_in_IT^(-theta)*Ttil_in_IT*Trade_shares_IT_ch(1,2)+tau_ch_eu_IT^(-theta)*Ttil_eu_IT*Trade_shares_IT_ch(1,3)+...
    tau_ch_ca_IT^(-theta)*Ttil_ca_IT*Trade_shares_IT_ch(1,4)+Ttil_ch_IT*Trade_shares_IT_ch(1,5)+tau_ch_ot_IT^(-theta)*Ttil_ot_IT*Trade_shares_IT_ch(1,6))^(-1/theta);
p_ch_Man=(tau_ch_us_Man^(-theta)*Ttil_us_Man*Trade_shares_Man_ch(1,1)+tau_ch_in_Man^(-theta)*Ttil_in_Man*Trade_shares_Man_ch(1,2)+tau_ch_eu_Man^(-theta)*Ttil_eu_Man*Trade_shares_Man_ch(1,3)+...
    tau_ch_ca_Man^(-theta)*Ttil_ca_Man*Trade_shares_Man_ch(1,4)+Ttil_ch_Man*Trade_shares_Man_ch(1,5)+tau_ch_ot_Man^(-theta)*Ttil_ot_Man*Trade_shares_Man_ch(1,6))^(-1/theta);
p_ch_Oth=(tau_ch_us_Oth^(-theta)*Ttil_us_Oth*Trade_shares_Oth_ch(1,1)+tau_ch_in_Oth^(-theta)*Ttil_in_Oth*Trade_shares_Oth_ch(1,2)+tau_ch_eu_Oth^(-theta)*Ttil_eu_Oth*Trade_shares_Oth_ch(1,3)+...
    tau_ch_ca_Oth^(-theta)*Ttil_ca_Oth*Trade_shares_Oth_ch(1,4)+Ttil_ch_Oth*Trade_shares_Oth_ch(1,5)+tau_ch_ot_Man^(-theta)*Ttil_ot_Oth*Trade_shares_Oth_ch(1,6))^(-1/theta);
p_ch_Fin=(tau_ch_us_Fin^(-theta)*Ttil_us_Fin*Trade_shares_Fin_ch(1,1)+tau_ch_in_Fin^(-theta)*Ttil_in_Fin*Trade_shares_Fin_ch(1,2)+tau_ch_eu_Fin^(-theta)*Ttil_eu_Fin*Trade_shares_Fin_ch(1,3)+...
    tau_ch_ca_Fin^(-theta)*Ttil_ca_Fin*Trade_shares_Fin_ch(1,4)+Ttil_ch_Fin*Trade_shares_Fin_ch(1,5)+tau_ch_ot_Fin^(-theta)*Ttil_ot_Fin*Trade_shares_Fin_ch(1,6))^(-1/theta);


p_ot_IT=(tau_ot_us_IT^(-theta)*Ttil_us_IT*Trade_shares_IT_ot(1,1)+tau_ot_in_IT^(-theta)*Ttil_in_IT*Trade_shares_IT_ot(1,2)+tau_ot_eu_IT^(-theta)*Ttil_eu_IT*Trade_shares_IT_ot(1,3)+...
    tau_ot_ca_IT^(-theta)*Ttil_ca_IT*Trade_shares_IT_ot(1,4)+tau_ot_ch_IT^(-theta)*Ttil_ch_IT*Trade_shares_IT_ot(1,5)+Ttil_ot_IT*Trade_shares_IT_ot(1,6))^(-1/theta);
p_ot_Man=(tau_ot_us_Man^(-theta)*Ttil_us_Man*Trade_shares_Man_ot(1,1)+tau_ot_in_Man^(-theta)*Ttil_in_Man*Trade_shares_Man_ot(1,2)+tau_ot_eu_Man^(-theta)*Ttil_eu_Man*Trade_shares_Man_ot(1,3)+...
    tau_ot_ca_Man^(-theta)*Ttil_ca_Man*Trade_shares_Man_ot(1,4)+tau_ot_ch_Man^(-theta)*Ttil_ch_Man*Trade_shares_Man_ot(1,5)+Ttil_ot_Man*Trade_shares_Man_ot(1,6))^(-1/theta);
p_ot_Oth=(tau_ot_us_Oth^(-theta)*Ttil_us_Oth*Trade_shares_Oth_ot(1,1)+tau_ot_in_Oth^(-theta)*Ttil_in_Oth*Trade_shares_Oth_ot(1,2)+tau_ot_eu_Oth^(-theta)*Ttil_eu_Oth*Trade_shares_Oth_ot(1,3)+...
    tau_ot_ca_Oth^(-theta)*Ttil_ca_Oth*Trade_shares_Oth_ot(1,4)+tau_ot_ch_Oth^(-theta)*Ttil_ch_Oth*Trade_shares_Oth_ot(1,5)+Ttil_ot_Oth*Trade_shares_Oth_ot(1,6))^(-1/theta);
p_ot_Fin=(tau_ot_us_Fin^(-theta)*Ttil_us_Fin*Trade_shares_Fin_ot(1,1)+tau_ot_in_Fin^(-theta)*Ttil_in_Fin*Trade_shares_Fin_ot(1,2)+tau_ot_eu_Fin^(-theta)*Ttil_eu_Fin*Trade_shares_Fin_ot(1,3)+...
    tau_ot_ca_Fin^(-theta)*Ttil_ca_Fin*Trade_shares_Fin_ot(1,4)+tau_ot_ch_Fin^(-theta)*Ttil_ch_Fin*Trade_shares_Fin_ot(1,5)+Ttil_ot_Fin*Trade_shares_Fin_ot(1,6))^(-1/theta);


%Trade shares


%US
trade_us_us_IT=Ttil_us_IT/p_us_IT^(-theta);
trade_us_in_IT=tau_us_in_IT^(-theta)*Ttil_in_IT/p_us_IT^(-theta);
trade_us_eu_IT=tau_us_eu_IT^(-theta)*Ttil_eu_IT/p_us_IT^(-theta);
trade_us_ca_IT=tau_us_ca_IT^(-theta)*Ttil_ca_IT/p_us_IT^(-theta);
trade_us_ch_IT=tau_us_ch_IT^(-theta)*Ttil_ch_IT/p_us_IT^(-theta);
trade_us_ot_IT=tau_us_ot_IT^(-theta)*Ttil_ot_IT/p_us_IT^(-theta);


trade_us_us_Man=Ttil_us_Man/p_us_Man^(-theta);
trade_us_in_Man=tau_us_in_Man^(-theta)*Ttil_in_Man/p_us_Man^(-theta);
trade_us_eu_Man=tau_us_eu_Man^(-theta)*Ttil_eu_Man/p_us_Man^(-theta);
trade_us_ca_Man=tau_us_ca_Man^(-theta)*Ttil_ca_Man/p_us_Man^(-theta);
trade_us_ch_Man=tau_us_ch_Man^(-theta)*Ttil_ch_Man/p_us_Man^(-theta);
trade_us_ot_Man=tau_us_ot_Man^(-theta)*Ttil_ot_Man/p_us_Man^(-theta);

trade_us_us_Oth=Ttil_us_Oth/p_us_Oth^(-theta);
trade_us_in_Oth=tau_us_in_Oth^(-theta)*Ttil_in_Oth/p_us_Oth^(-theta);
trade_us_eu_Oth=tau_us_eu_Oth^(-theta)*Ttil_eu_Oth/p_us_Oth^(-theta);
trade_us_ca_Oth=tau_us_ca_Oth^(-theta)*Ttil_ca_Oth/p_us_Oth^(-theta);
trade_us_ch_Oth=tau_us_ch_Oth^(-theta)*Ttil_ch_Oth/p_us_Oth^(-theta);
trade_us_ot_Oth=tau_us_ot_Oth^(-theta)*Ttil_ot_Oth/p_us_Oth^(-theta);

trade_us_us_Fin=Ttil_us_Fin/p_us_Fin^(-theta);
trade_us_in_Fin=tau_us_in_Fin^(-theta)*Ttil_in_Fin/p_us_Fin^(-theta);
trade_us_eu_Fin=tau_us_eu_Fin^(-theta)*Ttil_eu_Fin/p_us_Fin^(-theta);
trade_us_ca_Fin=tau_us_ca_Fin^(-theta)*Ttil_ca_Fin/p_us_Fin^(-theta);
trade_us_ch_Fin=tau_us_ch_Fin^(-theta)*Ttil_ch_Fin/p_us_Fin^(-theta);
trade_us_ot_Fin=tau_us_ot_Fin^(-theta)*Ttil_ot_Fin/p_us_Fin^(-theta);



%India

trade_in_us_IT=tau_in_us_IT^(-theta)*Ttil_us_IT/p_in_IT^(-theta);
trade_in_in_IT=Ttil_in_IT/p_in_IT^(-theta);
trade_in_eu_IT=tau_in_eu_IT^(-theta)*Ttil_eu_IT/p_in_IT^(-theta);
trade_in_ca_IT=tau_in_ca_IT^(-theta)*Ttil_ca_IT/p_in_IT^(-theta);
trade_in_ch_IT=tau_in_ch_IT^(-theta)*Ttil_ch_IT/p_in_IT^(-theta);
trade_in_ot_IT=tau_in_ot_IT^(-theta)*Ttil_ot_IT/p_in_IT^(-theta);


trade_in_us_Man=tau_in_us_Man^(-theta)*Ttil_us_Man/p_in_Man^(-theta);
trade_in_in_Man=Ttil_in_Man/p_in_Man^(-theta);
trade_in_eu_Man=tau_in_eu_Man^(-theta)*Ttil_eu_Man/p_in_Man^(-theta);
trade_in_ca_Man=tau_in_ca_Man^(-theta)*Ttil_ca_Man/p_in_Man^(-theta);
trade_in_ch_Man=tau_in_ch_Man^(-theta)*Ttil_ch_Man/p_in_Man^(-theta);
trade_in_ot_Man=tau_in_ot_Man^(-theta)*Ttil_ot_Man/p_in_Man^(-theta);

trade_in_us_Oth=tau_in_us_Oth^(-theta)*Ttil_us_Oth/p_in_Oth^(-theta);
trade_in_in_Oth=Ttil_in_Oth/p_in_Oth^(-theta);
trade_in_eu_Oth=tau_in_eu_Oth^(-theta)*Ttil_eu_Oth/p_in_Oth^(-theta);
trade_in_ca_Oth=tau_in_ca_Oth^(-theta)*Ttil_ca_Oth/p_in_Oth^(-theta);
trade_in_ch_Oth=tau_in_ch_Oth^(-theta)*Ttil_ch_Oth/p_in_Oth^(-theta);
trade_in_ot_Oth=tau_in_ot_Oth^(-theta)*Ttil_ot_Oth/p_in_Oth^(-theta);

trade_in_us_Fin=tau_in_us_Fin^(-theta)*Ttil_us_Fin/p_in_Fin^(-theta);
trade_in_in_Fin=Ttil_in_Fin/p_in_Fin^(-theta);
trade_in_eu_Fin=tau_in_eu_Fin^(-theta)*Ttil_eu_Fin/p_in_Fin^(-theta);
trade_in_ca_Fin=tau_in_ca_Fin^(-theta)*Ttil_ca_Fin/p_in_Fin^(-theta);
trade_in_ch_Fin=tau_in_ch_Fin^(-theta)*Ttil_ch_Fin/p_in_Fin^(-theta);
trade_in_ot_Fin=tau_in_ot_Fin^(-theta)*Ttil_ot_Fin/p_in_Fin^(-theta);

%Europe


trade_eu_us_IT=tau_eu_us_IT^(-theta)*Ttil_us_IT/p_eu_IT^(-theta);
trade_eu_in_IT=tau_eu_in_IT^(-theta)*Ttil_in_IT/p_eu_IT^(-theta);
trade_eu_eu_IT=Ttil_eu_IT/p_eu_IT^(-theta);
trade_eu_ca_IT=tau_eu_ca_IT^(-theta)*Ttil_ca_IT/p_eu_IT^(-theta);
trade_eu_ch_IT=tau_eu_ch_IT^(-theta)*Ttil_ch_IT/p_eu_IT^(-theta);
trade_eu_ot_IT=tau_eu_ot_IT^(-theta)*Ttil_ot_IT/p_eu_IT^(-theta);


trade_eu_us_Man=tau_eu_us_Man^(-theta)*Ttil_us_Man/p_eu_Man^(-theta);
trade_eu_in_Man=tau_eu_in_Man^(-theta)*Ttil_in_Man/p_eu_Man^(-theta);
trade_eu_eu_Man=Ttil_eu_Man/p_eu_Man^(-theta);
trade_eu_ca_Man=tau_eu_ca_Man^(-theta)*Ttil_ca_Man/p_eu_Man^(-theta);
trade_eu_ch_Man=tau_eu_ch_Man^(-theta)*Ttil_ch_Man/p_eu_Man^(-theta);
trade_eu_ot_Man=tau_eu_ot_Man^(-theta)*Ttil_ot_Man/p_eu_Man^(-theta);

trade_eu_us_Oth=tau_eu_us_Oth^(-theta)*Ttil_us_Oth/p_eu_Oth^(-theta);
trade_eu_in_Oth=tau_eu_in_Oth^(-theta)*Ttil_in_Oth/p_eu_Oth^(-theta);
trade_eu_eu_Oth=Ttil_eu_Oth/p_eu_Oth^(-theta);
trade_eu_ca_Oth=tau_eu_ca_Oth^(-theta)*Ttil_ca_Oth/p_eu_Oth^(-theta);
trade_eu_ch_Oth=tau_eu_ch_Oth^(-theta)*Ttil_ch_Oth/p_eu_Oth^(-theta);
trade_eu_ot_Oth=tau_eu_ot_Oth^(-theta)*Ttil_ot_Oth/p_eu_Oth^(-theta);

trade_eu_us_Fin=tau_eu_us_Fin^(-theta)*Ttil_us_Fin/p_eu_Fin^(-theta);
trade_eu_in_Fin=tau_eu_in_Fin^(-theta)*Ttil_in_Fin/p_eu_Fin^(-theta);
trade_eu_eu_Fin=Ttil_eu_Fin/p_eu_Fin^(-theta);
trade_eu_ca_Fin=tau_eu_ca_Fin^(-theta)*Ttil_ca_Fin/p_eu_Fin^(-theta);
trade_eu_ch_Fin=tau_eu_ch_Fin^(-theta)*Ttil_ch_Fin/p_eu_Fin^(-theta);
trade_eu_ot_Fin=tau_eu_ot_Fin^(-theta)*Ttil_ot_Fin/p_eu_Fin^(-theta);

%Canada

trade_ca_us_IT=tau_ca_us_IT^(-theta)*Ttil_us_IT/p_ca_IT^(-theta);
trade_ca_in_IT=tau_ca_in_IT^(-theta)*Ttil_in_IT/p_ca_IT^(-theta);
trade_ca_eu_IT=tau_ca_eu_IT^(-theta)*Ttil_eu_IT/p_ca_IT^(-theta);
trade_ca_ca_IT=Ttil_ca_IT/p_ca_IT^(-theta);
trade_ca_ch_IT=tau_ca_ch_IT^(-theta)*Ttil_ch_IT/p_ca_IT^(-theta);
trade_ca_ot_IT=tau_ca_ot_IT^(-theta)*Ttil_ot_IT/p_ca_IT^(-theta);


trade_ca_us_Man=tau_ca_us_Man^(-theta)*Ttil_us_Man/p_ca_Man^(-theta);
trade_ca_in_Man=tau_ca_in_Man^(-theta)*Ttil_in_Man/p_ca_Man^(-theta);
trade_ca_eu_Man=tau_ca_eu_Man^(-theta)*Ttil_eu_Man/p_ca_Man^(-theta);
trade_ca_ca_Man=Ttil_ca_Man/p_ca_Man^(-theta);
trade_ca_ch_Man=tau_ca_ch_Man^(-theta)*Ttil_ch_Man/p_ca_Man^(-theta);
trade_ca_ot_Man=tau_ca_ot_Man^(-theta)*Ttil_ot_Man/p_ca_Man^(-theta);

trade_ca_us_Oth=tau_ca_us_Oth^(-theta)*Ttil_us_Oth/p_ca_Oth^(-theta);
trade_ca_in_Oth=tau_ca_in_Oth^(-theta)*Ttil_in_Oth/p_ca_Oth^(-theta);
trade_ca_eu_Oth=tau_ca_eu_Oth^(-theta)*Ttil_eu_Oth/p_ca_Oth^(-theta);
trade_ca_ca_Oth=Ttil_ca_Oth/p_ca_Oth^(-theta);
trade_ca_ch_Oth=tau_ca_ch_Oth^(-theta)*Ttil_ch_Oth/p_ca_Oth^(-theta);
trade_ca_ot_Oth=tau_ca_ot_Oth^(-theta)*Ttil_ot_Oth/p_ca_Oth^(-theta);

trade_ca_us_Fin=tau_ca_us_Fin^(-theta)*Ttil_us_Fin/p_ca_Fin^(-theta);
trade_ca_in_Fin=tau_ca_in_Fin^(-theta)*Ttil_in_Fin/p_ca_Fin^(-theta);
trade_ca_eu_Fin=tau_ca_eu_Fin^(-theta)*Ttil_eu_Fin/p_ca_Fin^(-theta);
trade_ca_ca_Fin=Ttil_ca_Fin/p_ca_Fin^(-theta);
trade_ca_ch_Fin=tau_ca_ch_Fin^(-theta)*Ttil_ch_Fin/p_ca_Fin^(-theta);
trade_ca_ot_Fin=tau_ca_ot_Fin^(-theta)*Ttil_ot_Fin/p_ca_Fin^(-theta);

%China

trade_ch_us_IT=tau_ch_us_IT^(-theta)*Ttil_us_IT/p_ch_IT^(-theta);
trade_ch_in_IT=tau_ch_in_IT^(-theta)*Ttil_in_IT/p_ch_IT^(-theta);
trade_ch_eu_IT=tau_ch_eu_IT^(-theta)*Ttil_eu_IT/p_ch_IT^(-theta);
trade_ch_ca_IT=tau_ch_ca_IT^(-theta)*Ttil_ca_IT/p_ch_IT^(-theta);
trade_ch_ch_IT=Ttil_ch_IT/p_ch_IT^(-theta);
trade_ch_ot_IT=tau_ch_ot_IT^(-theta)*Ttil_ot_IT/p_ch_IT^(-theta);


trade_ch_us_Man=tau_ch_us_Man^(-theta)*Ttil_us_Man/p_ch_Man^(-theta);
trade_ch_in_Man=tau_ch_in_Man^(-theta)*Ttil_in_Man/p_ch_Man^(-theta);
trade_ch_eu_Man=tau_ch_eu_Man^(-theta)*Ttil_eu_Man/p_ch_Man^(-theta);
trade_ch_ca_Man=tau_ch_ca_Man^(-theta)*Ttil_ca_Man/p_ch_Man^(-theta);
trade_ch_ch_Man=Ttil_ch_Man/p_ch_Man^(-theta);
trade_ch_ot_Man=tau_ch_ot_Man^(-theta)*Ttil_ot_Man/p_ch_Man^(-theta);

trade_ch_us_Oth=tau_ch_us_Oth^(-theta)*Ttil_us_Oth/p_ch_Oth^(-theta);
trade_ch_in_Oth=tau_ch_in_Oth^(-theta)*Ttil_in_Oth/p_ch_Oth^(-theta);
trade_ch_eu_Oth=tau_ch_eu_Oth^(-theta)*Ttil_eu_Oth/p_ch_Oth^(-theta);
trade_ch_ca_Oth=tau_ch_ca_Oth^(-theta)*Ttil_ca_Oth/p_ch_Oth^(-theta);
trade_ch_ch_Oth=Ttil_ch_Oth/p_ch_Oth^(-theta);
trade_ch_ot_Oth=tau_ch_ot_Man^(-theta)*Ttil_ot_Oth/p_ch_Oth^(-theta);

trade_ch_us_Fin=tau_ch_us_Fin^(-theta)*Ttil_us_Fin/p_ch_Fin^(-theta);
trade_ch_in_Fin=tau_ch_in_Fin^(-theta)*Ttil_in_Fin/p_ch_Fin^(-theta);
trade_ch_eu_Fin=tau_ch_eu_Fin^(-theta)*Ttil_eu_Fin/p_ch_Fin^(-theta);
trade_ch_ca_Fin=tau_ch_ca_Fin^(-theta)*Ttil_ca_Fin/p_ch_Fin^(-theta);
trade_ch_ch_Fin=Ttil_ch_Fin/p_ch_Fin^(-theta);
trade_ch_ot_Fin=tau_ch_ot_Fin^(-theta)*Ttil_ot_Fin/p_ch_Fin^(-theta);

%Other

trade_ot_us_IT=tau_ot_us_IT^(-theta)*Ttil_us_IT/p_ot_IT^(-theta);
trade_ot_in_IT=tau_ot_in_IT^(-theta)*Ttil_in_IT/p_ot_IT^(-theta);
trade_ot_eu_IT=tau_ot_eu_IT^(-theta)*Ttil_eu_IT/p_ot_IT^(-theta);
trade_ot_ca_IT=tau_ot_ca_IT^(-theta)*Ttil_ca_IT/p_ot_IT^(-theta);
trade_ot_ch_IT=tau_ot_ch_IT^(-theta)*Ttil_ch_IT/p_ot_IT^(-theta);
trade_ot_ot_IT=Ttil_ot_IT/p_ot_IT^(-theta);


trade_ot_us_Man=tau_ot_us_Man^(-theta)*Ttil_us_Man/p_ot_Man^(-theta);
trade_ot_in_Man=tau_ot_in_Man^(-theta)*Ttil_in_Man/p_ot_Man^(-theta);
trade_ot_eu_Man=tau_ot_eu_Man^(-theta)*Ttil_eu_Man/p_ot_Man^(-theta);
trade_ot_ca_Man=tau_ot_ca_Man^(-theta)*Ttil_ca_Man/p_ot_Man^(-theta);
trade_ot_ch_Man=tau_ot_ch_Man^(-theta)*Ttil_ch_Man/p_ot_Man^(-theta);
trade_ot_ot_Man=Ttil_ot_Man/p_ot_Man^(-theta);

trade_ot_us_Oth=tau_ot_us_Oth^(-theta)*Ttil_us_Oth/p_ot_Oth^(-theta);
trade_ot_in_Oth=tau_ot_in_Oth^(-theta)*Ttil_in_Oth/p_ot_Oth^(-theta);
trade_ot_eu_Oth=tau_ot_eu_Oth^(-theta)*Ttil_eu_Oth/p_ot_Oth^(-theta);
trade_ot_ca_Oth=tau_ot_ca_Oth^(-theta)*Ttil_ca_Oth/p_ot_Oth^(-theta);
trade_ot_ch_Oth=tau_ot_ch_Oth^(-theta)*Ttil_ch_Oth/p_ot_Oth^(-theta);
trade_ot_ot_Oth=Ttil_ot_Oth/p_ot_Oth^(-theta);

trade_ot_us_Fin=tau_ot_us_Fin^(-theta)*Ttil_us_Fin/p_ot_Fin^(-theta);
trade_ot_in_Fin=tau_ot_in_Fin^(-theta)*Ttil_in_Fin/p_ot_Fin^(-theta);
trade_ot_eu_Fin=tau_ot_eu_Fin^(-theta)*Ttil_eu_Fin/p_ot_Fin^(-theta);
trade_ot_ca_Fin=tau_ot_ca_Fin^(-theta)*Ttil_ca_Fin/p_ot_Fin^(-theta);
trade_ot_ch_Fin=tau_ot_ch_Fin^(-theta)*Ttil_ch_Fin/p_ot_Fin^(-theta);
trade_ot_ot_Fin=Ttil_ot_Fin/p_ot_Fin^(-theta);


%MNE shares

mne_us_us_IT=1;
mne_us_us_Man=1;
mne_us_us_Fin=1;

mne_in_in_IT=1;
mne_in_in_Man=1;
mne_in_in_Fin=1;

mne_eu_eu_IT=1;
mne_eu_eu_Man=1;
mne_eu_eu_Fin=1;

mne_ca_ca_IT=1;
mne_ca_ca_Man=1;
mne_ca_ca_Fin=1;

mne_ch_ch_IT=1;
mne_ch_ch_Man=1;
mne_ch_ch_Fin=1;

%Total expenditure

exp_us=L_us*w_us_L*(total_shares_us_us(1,3)+total_shares_us_us(1,6)+total_shares_us_us(1,9))+...
w_us_IT_us_d*h_us_IT_us_d*total_shares_us_us(1,1)+...
w_us_IT_us_f*h_us_IT_us_f*total_shares_us_us(1,2)+...
w_us_Man_us_d*h_us_Man_us_d*total_shares_us_us(1,4)+...
w_us_Man_us_f*h_us_Man_us_f*total_shares_us_us(1,5)+...
w_us_Oth_us_d*h_us_Oth_us_d*total_shares_us_us(1,7)+...
w_us_Oth_us_f*h_us_Oth_us_f*total_shares_us_us(1,8)+...
L_us*w_us_L*(total_shares_us_us(1,12))+...
w_us_Fin_us_d*h_us_Fin_us_d*total_shares_us_us(1,10)+...
w_us_Fin_us_f*h_us_Fin_us_f*total_shares_us_us(1,11);



exp_in=L_in*w_in_L*(total_shares_in_in(1,4)+total_shares_in_in(1,5)+total_shares_in_in(1,6))+...
w_in_IT_in*h_in_IT_in*total_shares_in_in(1,1)+...
w_in_Man_in*h_in_Man_in*total_shares_in_in(1,2)+...
w_in_Oth_in*h_in_Oth_in*total_shares_in_in(1,3)+...
L_in*w_in_L*(total_shares_in_in(1,8))+...
w_in_Fin_in*h_in_Fin_in*total_shares_in_in(1,7);


exp_eu=L_eu*w_eu_L*(total_shares_eu_eu(1,3)+total_shares_eu_eu(1,6)+total_shares_eu_eu(1,9))+...
w_eu_IT_eu_d*h_eu_IT_eu_d*total_shares_eu_eu(1,1)+...
w_eu_IT_eu_f*h_eu_IT_eu_f*total_shares_eu_eu(1,2)+...
w_eu_Man_eu_d*h_eu_Man_eu_d*total_shares_eu_eu(1,4)+...
w_eu_Man_eu_f*h_eu_Man_eu_f*total_shares_eu_eu(1,5)+...
w_eu_Oth_eu_d*h_eu_Oth_eu_d*total_shares_eu_eu(1,7)+...
w_eu_Oth_eu_f*h_eu_Oth_eu_f*total_shares_eu_eu(1,8)+...
L_eu*w_eu_L*(total_shares_eu_eu(1,12))+...
w_eu_Fin_eu_d*h_eu_Fin_eu_d*total_shares_eu_eu(1,10)+...
w_eu_Fin_eu_f*h_eu_Fin_eu_f*total_shares_eu_eu(1,11);



exp_ca=L_ca*w_ca_L*(total_shares_ca_ca(1,3)+total_shares_ca_ca(1,6)+total_shares_ca_ca(1,9))+...
w_ca_IT_ca_d*h_ca_IT_ca_d*total_shares_ca_ca(1,1)+...
w_ca_IT_ca_f*h_ca_IT_ca_f*total_shares_ca_ca(1,2)+...
w_ca_Man_ca_d*h_ca_Man_ca_d*total_shares_ca_ca(1,4)+...
w_ca_Man_ca_f*h_ca_Man_ca_f*total_shares_ca_ca(1,5)+...
w_ca_Oth_ca_d*h_ca_Oth_ca_d*total_shares_ca_ca(1,7)+...
w_ca_Oth_ca_f*h_ca_Oth_ca_f*total_shares_ca_ca(1,8)+...
L_ca*w_ca_L*(total_shares_ca_ca(1,12))+...
w_ca_Fin_ca_d*h_ca_Fin_ca_d*total_shares_ca_ca(1,10)+...
w_ca_Fin_ca_f*h_ca_Fin_ca_f*total_shares_ca_ca(1,11);



exp_ch=L_ch*w_ch_L*(total_shares_ch_ch(1,4)+total_shares_ch_ch(1,5)+total_shares_ch_ch(1,6))+...
w_ch_IT_ch*h_ch_IT_ch*total_shares_ch_ch(1,1)+...
w_ch_Man_ch*h_ch_Man_ch*total_shares_ch_ch(1,2)+...
w_ch_Oth_ch*h_ch_Oth_ch*total_shares_ch_ch(1,3)+...
L_ch*w_ch_L*(total_shares_ch_ch(1,8))+...
w_ch_Fin_ch*h_ch_Fin_ch*total_shares_ch_ch(1,7);


% exp_ot=L_ot*w_ot_L*(total_shares_ot(1,4)+total_shares_ot(1,5)+total_shares_ot(1,6))+...
% w_ot_IT_ot*h_ot_IT_ot*total_shares_ot(1,1)+...
% w_ot_Man_ot*h_ot_Man_ot*total_shares_ot(1,2)+...
% w_ot_Oth_ot*h_ot_Oth_ot*total_shares_ot(1,3);


%Normalization

exp_ot=(1-exp_in*Share_World_GDP(1,2)-exp_eu*Share_World_GDP(1,3)-exp_ca*Share_World_GDP(1,4)-exp_ch*Share_World_GDP(1,5)-exp_us*Share_World_GDP(1,1))/Share_World_GDP(1,6);




%Income

inc_us_IT=trade_us_us_IT*exp_us*Prod_shares_IT_us(1,1)+trade_in_us_IT*exp_in*Prod_shares_IT_us(1,2)+trade_eu_us_IT*exp_eu*Prod_shares_IT_us(1,3)+trade_ca_us_IT*exp_ca*Prod_shares_IT_us(1,4)+trade_ch_us_IT*exp_ch*Prod_shares_IT_us(1,5)+trade_ot_us_IT*exp_ot*Prod_shares_IT_us(1,6);
inc_us_Man=trade_us_us_Man*exp_us*Prod_shares_Man_us(1,1)+trade_in_us_Man*exp_in*Prod_shares_Man_us(1,2)+trade_eu_us_Man*exp_eu*Prod_shares_Man_us(1,3)+trade_ca_us_Man*exp_ca*Prod_shares_Man_us(1,4)+trade_ch_us_Man*exp_ch*Prod_shares_Man_us(1,5)+trade_ot_us_Man*exp_ot*Prod_shares_Man_us(1,6);
inc_us_Oth=trade_us_us_Oth*exp_us*Prod_shares_Oth_us(1,1)+trade_in_us_Oth*exp_in*Prod_shares_Oth_us(1,2)+trade_eu_us_Oth*exp_eu*Prod_shares_Oth_us(1,3)+trade_ca_us_Oth*exp_ca*Prod_shares_Oth_us(1,4)+trade_ch_us_Oth*exp_ch*Prod_shares_Oth_us(1,5)+trade_ot_us_Oth*exp_ot*Prod_shares_Oth_us(1,6);
inc_us_Fin=trade_us_us_Fin*exp_us*Prod_shares_Fin_us(1,1)+trade_in_us_Fin*exp_in*Prod_shares_Fin_us(1,2)+trade_eu_us_Fin*exp_eu*Prod_shares_Fin_us(1,3)+trade_ca_us_Fin*exp_ca*Prod_shares_Fin_us(1,4)+trade_ch_us_Fin*exp_ch*Prod_shares_Fin_us(1,5)+trade_ot_us_Fin*exp_ot*Prod_shares_Fin_us(1,6);


inc_in_IT=trade_us_in_IT*exp_us*Prod_shares_IT_in(1,1)+trade_in_in_IT*exp_in*Prod_shares_IT_in(1,2)+trade_eu_in_IT*exp_eu*Prod_shares_IT_in(1,3)+trade_ca_in_IT*exp_ca*Prod_shares_IT_in(1,4)+trade_ch_in_IT*exp_ch*Prod_shares_IT_in(1,5)+trade_ot_in_IT*exp_ot*Prod_shares_IT_in(1,6);
inc_in_Man=trade_us_in_Man*exp_us*Prod_shares_Man_in(1,1)+trade_in_in_Man*exp_in*Prod_shares_Man_in(1,2)+trade_eu_in_Man*exp_eu*Prod_shares_Man_in(1,3)+trade_ca_in_Man*exp_ca*Prod_shares_Man_in(1,4)+trade_ch_in_Man*exp_ch*Prod_shares_Man_in(1,5)+trade_ot_in_Man*exp_ot*Prod_shares_Man_in(1,6);
inc_in_Oth=trade_us_in_Oth*exp_us*Prod_shares_Oth_in(1,1)+trade_in_in_Oth*exp_in*Prod_shares_Oth_in(1,2)+trade_eu_in_Oth*exp_eu*Prod_shares_Oth_in(1,3)+trade_ca_in_Oth*exp_ca*Prod_shares_Oth_in(1,4)+trade_ch_in_Oth*exp_ch*Prod_shares_Oth_in(1,5)+trade_ot_in_Oth*exp_ot*Prod_shares_Oth_in(1,6);
inc_in_Fin=trade_us_in_Fin*exp_us*Prod_shares_Fin_in(1,1)+trade_in_in_Fin*exp_in*Prod_shares_Fin_in(1,2)+trade_eu_in_Fin*exp_eu*Prod_shares_Fin_in(1,3)+trade_ca_in_Fin*exp_ca*Prod_shares_Fin_in(1,4)+trade_ch_in_Fin*exp_ch*Prod_shares_Fin_in(1,5)+trade_ot_in_Fin*exp_ot*Prod_shares_Fin_in(1,6);

inc_eu_IT=trade_us_eu_IT*exp_us*Prod_shares_IT_eu(1,1)+trade_in_eu_IT*exp_in*Prod_shares_IT_eu(1,2)+trade_eu_eu_IT*exp_eu*Prod_shares_IT_eu(1,3)+trade_ca_eu_IT*exp_ca*Prod_shares_IT_eu(1,4)+trade_ch_eu_IT*exp_ch*Prod_shares_IT_eu(1,5)+trade_ot_eu_IT*exp_ot*Prod_shares_IT_eu(1,6);
inc_eu_Man=trade_us_eu_Man*exp_us*Prod_shares_Man_eu(1,1)+trade_in_eu_Man*exp_in*Prod_shares_Man_eu(1,2)+trade_eu_eu_Man*exp_eu*Prod_shares_Man_eu(1,3)+trade_ca_eu_Man*exp_ca*Prod_shares_Man_eu(1,4)+trade_ch_eu_Man*exp_ch*Prod_shares_Man_eu(1,5)+trade_ot_eu_Man*exp_ot*Prod_shares_Man_eu(1,6);
inc_eu_Oth=trade_us_eu_Oth*exp_us*Prod_shares_Oth_eu(1,1)+trade_in_eu_Oth*exp_in*Prod_shares_Oth_eu(1,2)+trade_eu_eu_Oth*exp_eu*Prod_shares_Oth_eu(1,3)+trade_ca_eu_Oth*exp_ca*Prod_shares_Oth_eu(1,4)+trade_ch_eu_Oth*exp_ch*Prod_shares_Oth_eu(1,5)+trade_ot_eu_Oth*exp_ot*Prod_shares_Oth_eu(1,6);
inc_eu_Fin=trade_us_eu_Fin*exp_us*Prod_shares_Fin_eu(1,1)+trade_in_eu_Fin*exp_in*Prod_shares_Fin_eu(1,2)+trade_eu_eu_Fin*exp_eu*Prod_shares_Fin_eu(1,3)+trade_ca_eu_Fin*exp_ca*Prod_shares_Fin_eu(1,4)+trade_ch_eu_Fin*exp_ch*Prod_shares_Fin_eu(1,5)+trade_ot_eu_Fin*exp_ot*Prod_shares_Fin_eu(1,6);

inc_ca_IT=trade_us_ca_IT*exp_us*Prod_shares_IT_ca(1,1)+trade_in_ca_IT*exp_in*Prod_shares_IT_ca(1,2)+trade_eu_ca_IT*exp_eu*Prod_shares_IT_ca(1,3)+trade_ca_ca_IT*exp_ca*Prod_shares_IT_ca(1,4)+trade_ch_ca_IT*exp_ch*Prod_shares_IT_ca(1,5)+trade_ot_ca_IT*exp_ot*Prod_shares_IT_ca(1,6);
inc_ca_Man=trade_us_ca_Man*exp_us*Prod_shares_Man_ca(1,1)+trade_in_ca_Man*exp_in*Prod_shares_Man_ca(1,2)+trade_eu_ca_Man*exp_eu*Prod_shares_Man_ca(1,3)+trade_ca_ca_Man*exp_ca*Prod_shares_Man_ca(1,4)+trade_ch_ca_Man*exp_ch*Prod_shares_Man_ca(1,5)+trade_ot_ca_Man*exp_ot*Prod_shares_Man_ca(1,6);
inc_ca_Oth=trade_us_ca_Oth*exp_us*Prod_shares_Oth_ca(1,1)+trade_in_ca_Oth*exp_in*Prod_shares_Oth_ca(1,2)+trade_eu_ca_Oth*exp_eu*Prod_shares_Oth_ca(1,3)+trade_ca_ca_Oth*exp_ca*Prod_shares_Oth_ca(1,4)+trade_ch_ca_Oth*exp_ch*Prod_shares_Oth_ca(1,5)+trade_ot_ca_Oth*exp_ot*Prod_shares_Oth_ca(1,6);
inc_ca_Fin=trade_us_ca_Fin*exp_us*Prod_shares_Fin_ca(1,1)+trade_in_ca_Fin*exp_in*Prod_shares_Fin_ca(1,2)+trade_eu_ca_Fin*exp_eu*Prod_shares_Fin_ca(1,3)+trade_ca_ca_Fin*exp_ca*Prod_shares_Fin_ca(1,4)+trade_ch_ca_Fin*exp_ch*Prod_shares_Fin_ca(1,5)+trade_ot_ca_Fin*exp_ot*Prod_shares_Fin_ca(1,6);

inc_ch_IT=trade_us_ch_IT*exp_us*Prod_shares_IT_ch(1,1)+trade_in_ch_IT*exp_in*Prod_shares_IT_ch(1,2)+trade_eu_ch_IT*exp_eu*Prod_shares_IT_ch(1,3)+trade_ca_ch_IT*exp_ca*Prod_shares_IT_ch(1,4)+trade_ch_ch_IT*exp_ch*Prod_shares_IT_ch(1,5)+trade_ot_ch_IT*exp_ot*Prod_shares_IT_ch(1,6);
inc_ch_Man=trade_us_ch_Man*exp_us*Prod_shares_Man_ch(1,1)+trade_in_ch_Man*exp_in*Prod_shares_Man_ch(1,2)+trade_eu_ch_Man*exp_eu*Prod_shares_Man_ch(1,3)+trade_ca_ch_Man*exp_ca*Prod_shares_Man_ch(1,4)+trade_ch_ch_Man*exp_ch*Prod_shares_Man_ch(1,5)+trade_ot_ch_Man*exp_ot*Prod_shares_Man_ch(1,6);
inc_ch_Oth=trade_us_ch_Oth*exp_us*Prod_shares_Oth_ch(1,1)+trade_in_ch_Oth*exp_in*Prod_shares_Oth_ch(1,2)+trade_eu_ch_Oth*exp_eu*Prod_shares_Oth_ch(1,3)+trade_ca_ch_Oth*exp_ca*Prod_shares_Oth_ch(1,4)+trade_ch_ch_Oth*exp_ch*Prod_shares_Oth_ch(1,5)+trade_ot_ch_Oth*exp_ot*Prod_shares_Oth_ch(1,6);
inc_ch_Fin=trade_us_ch_Fin*exp_us*Prod_shares_Fin_ch(1,1)+trade_in_ch_Fin*exp_in*Prod_shares_Fin_ch(1,2)+trade_eu_ch_Fin*exp_eu*Prod_shares_Fin_ch(1,3)+trade_ca_ch_Fin*exp_ca*Prod_shares_Fin_ch(1,4)+trade_ch_ch_Fin*exp_ch*Prod_shares_Fin_ch(1,5)+trade_ot_ch_Fin*exp_ot*Prod_shares_Fin_ch(1,6);

inc_ot_IT=trade_us_ot_IT*exp_us*Prod_shares_IT_ot(1,1)+trade_in_ot_IT*exp_in*Prod_shares_IT_ot(1,2)+trade_eu_ot_IT*exp_eu*Prod_shares_IT_ot(1,3)+trade_ca_ot_IT*exp_ca*Prod_shares_IT_ot(1,4)+trade_ch_ot_IT*exp_ch*Prod_shares_IT_ot(1,5)+trade_ot_ot_IT*exp_ot*Prod_shares_IT_ot(1,6);
inc_ot_Man=trade_us_ot_Man*exp_us*Prod_shares_Man_ot(1,1)+trade_in_ot_Man*exp_in*Prod_shares_Man_ot(1,2)+trade_eu_ot_Man*exp_eu*Prod_shares_Man_ot(1,3)+trade_ca_ot_Man*exp_ca*Prod_shares_Man_ot(1,4)+trade_ch_ot_Man*exp_ch*Prod_shares_Man_ot(1,5)+trade_ot_ot_Man*exp_ot*Prod_shares_Man_ot(1,6);
inc_ot_Oth=trade_us_ot_Oth*exp_us*Prod_shares_Oth_ot(1,1)+trade_in_ot_Oth*exp_in*Prod_shares_Oth_ot(1,2)+trade_eu_ot_Oth*exp_eu*Prod_shares_Oth_ot(1,3)+trade_ca_ot_Oth*exp_ca*Prod_shares_Oth_ot(1,4)+trade_ch_ot_Oth*exp_ch*Prod_shares_Oth_ot(1,5)+trade_ot_ot_Oth*exp_ot*Prod_shares_Oth_ot(1,6);
inc_ot_Fin=trade_us_ot_Fin*exp_us*Prod_shares_Fin_ot(1,1)+trade_in_ot_Fin*exp_in*Prod_shares_Fin_ot(1,2)+trade_eu_ot_Fin*exp_eu*Prod_shares_Fin_ot(1,3)+trade_ca_ot_Fin*exp_ca*Prod_shares_Fin_ot(1,4)+trade_ch_ot_Fin*exp_ch*Prod_shares_Fin_ot(1,5)+trade_ot_ot_Fin*exp_ot*Prod_shares_Fin_ot(1,6);

%Low-skill labor supply

l_us_IT_us=inc_us_IT*mne_us_us_IT*lowshare_us_IT_us/w_us_L;
l_us_Man_us=inc_us_Man*mne_us_us_Man*lowshare_us_Man_us/w_us_L;
l_us_Oth_us=inc_us_Oth*lowshare_us_Oth_us/w_us_L;
l_us_Fin_us=inc_us_Fin*mne_us_us_Fin*lowshare_us_Fin_us/w_us_L;


%India

l_in_IT_in=inc_in_IT*mne_in_in_IT*lowshare_in_IT_in/w_in_L;
l_in_Man_in=inc_in_Man*mne_in_in_Man*lowshare_in_Man_in/w_in_L;
l_in_Oth_in=inc_in_Oth*lowshare_in_Oth_in/w_in_L;
l_in_Fin_in=inc_in_Fin*mne_in_in_Fin*lowshare_in_Fin_in/w_in_L;


%Europe


l_eu_IT_eu=inc_eu_IT*mne_eu_eu_IT*lowshare_eu_IT_eu/w_eu_L;
l_eu_Man_eu=inc_eu_Man*mne_eu_eu_Man*lowshare_eu_Man_eu/w_eu_L;
l_eu_Oth_eu=inc_eu_Oth*lowshare_eu_Oth_eu/w_eu_L;
l_eu_Fin_eu=inc_eu_Fin*mne_eu_eu_Fin*lowshare_eu_Fin_eu/w_eu_L;



%Canada


l_ca_IT_ca=inc_ca_IT*mne_ca_ca_IT*lowshare_ca_IT_ca/w_ca_L;
l_ca_Man_ca=inc_ca_Man*mne_ca_ca_Man*lowshare_ca_Man_ca/w_ca_L;
l_ca_Oth_ca=inc_ca_Oth*lowshare_ca_Oth_ca/w_ca_L;
l_ca_Fin_ca=inc_ca_Fin*mne_ca_ca_Fin*lowshare_ca_Fin_ca/w_ca_L;

%China


l_ch_IT_ch=inc_ch_IT*mne_ch_ch_IT*lowshare_ch_IT_ch/w_ch_L;
l_ch_Man_ch=inc_ch_Man*mne_ch_ch_Man*lowshare_ch_Man_ch/w_ch_L;
l_ch_Oth_ch=inc_ch_Oth*lowshare_ch_Oth_ch/w_ch_L;
l_ch_Fin_ch=inc_ch_Fin*mne_ch_ch_Fin*lowshare_ch_Fin_ch/w_ch_L;


%Other

l_ot_IT_ot=inc_ot_IT*lowshare_ot_IT_ot/w_ot_L;
l_ot_Man_ot=inc_ot_Man*lowshare_ot_Man_ot/w_ot_L;
l_ot_Oth_ot=inc_ot_Oth*lowshare_ot_Oth_ot/w_ot_L;
l_ot_Fin_ot=inc_ot_Fin*lowshare_ot_Fin_ot/w_ot_L;




%Market clearing equilibrium

%US

alt_h_us_IT_us_d=inc_us_IT*mne_us_us_IT*hshare_us_IT_us_d*highshare_us_IT_us/w_us_IT_us_d;
alt_h_us_IT_us_f=inc_us_IT*mne_us_us_IT*hshare_us_IT_us_f*highshare_us_IT_us/w_us_IT_us_f;

alt_h_us_Man_us_d=inc_us_Man*mne_us_us_Man*hshare_us_Man_us_d*highshare_us_Man_us/w_us_Man_us_d;
alt_h_us_Man_us_f=inc_us_Man*mne_us_us_Man*hshare_us_Man_us_f*highshare_us_Man_us/w_us_Man_us_f;

alt_h_us_Oth_us_d=inc_us_Oth*hshare_us_Oth_us_d*highshare_us_Oth_us/w_us_Oth_us_d;
alt_h_us_Oth_us_f=inc_us_Oth*hshare_us_Oth_us_f*highshare_us_Oth_us/w_us_Oth_us_f;

alt_h_us_Fin_us_d=inc_us_Fin*mne_us_us_Fin*hshare_us_Fin_us_d*highshare_us_Fin_us/w_us_Fin_us_d;
alt_h_us_Fin_us_f=inc_us_Fin*mne_us_us_Fin*hshare_us_Fin_us_f*highshare_us_Fin_us/w_us_Fin_us_f;


%Europe

alt_h_eu_IT_eu_d=inc_eu_IT*mne_eu_eu_IT*hshare_eu_IT_eu_d*highshare_eu_IT_eu/w_eu_IT_eu_d;
alt_h_eu_IT_eu_f=inc_eu_IT*mne_eu_eu_IT*hshare_eu_IT_eu_f*highshare_eu_IT_eu/w_eu_IT_eu_f;

alt_h_eu_Man_eu_d=inc_eu_Man*mne_eu_eu_Man*hshare_eu_Man_eu_d*highshare_eu_Man_eu/w_eu_Man_eu_d;
alt_h_eu_Man_eu_f=inc_eu_Man*mne_eu_eu_Man*hshare_eu_Man_eu_f*highshare_eu_Man_eu/w_eu_Man_eu_f;

alt_h_eu_Oth_eu_d=inc_eu_Oth*hshare_eu_Oth_eu_d*highshare_eu_Oth_eu/w_eu_Oth_eu_d;
alt_h_eu_Oth_eu_f=inc_eu_Oth*hshare_eu_Oth_eu_f*highshare_eu_Oth_eu/w_eu_Oth_eu_f;

alt_h_eu_Fin_eu_d=inc_eu_Fin*mne_eu_eu_Fin*hshare_eu_Fin_eu_d*highshare_eu_Fin_eu/w_eu_Fin_eu_d;
alt_h_eu_Fin_eu_f=inc_eu_Fin*mne_eu_eu_Fin*hshare_eu_Fin_eu_f*highshare_eu_Fin_eu/w_eu_Fin_eu_f;


%Canada

alt_h_ca_IT_ca_d=inc_ca_IT*mne_ca_ca_IT*hshare_ca_IT_ca_d*highshare_ca_IT_ca/w_ca_IT_ca_d;
alt_h_ca_IT_ca_f=inc_ca_IT*mne_ca_ca_IT*hshare_ca_IT_ca_f*highshare_ca_IT_ca/w_ca_IT_ca_f;

alt_h_ca_Man_ca_d=inc_ca_Man*mne_ca_ca_Man*hshare_ca_Man_ca_d*highshare_ca_Man_ca/w_ca_Man_ca_d;
alt_h_ca_Man_ca_f=inc_ca_Man*mne_ca_ca_Man*hshare_ca_Man_ca_f*highshare_ca_Man_ca/w_ca_Man_ca_f;

alt_h_ca_Oth_ca_d=inc_ca_Oth*hshare_ca_Oth_ca_d*highshare_ca_Oth_ca/w_ca_Oth_ca_d;
alt_h_ca_Oth_ca_f=inc_ca_Oth*hshare_ca_Oth_ca_f*highshare_ca_Oth_ca/w_ca_Oth_ca_f;

alt_h_ca_Fin_ca_d=inc_ca_Fin*mne_ca_ca_Fin*hshare_ca_Fin_ca_d*highshare_ca_Fin_ca/w_ca_Fin_ca_d;
alt_h_ca_Fin_ca_f=inc_ca_Fin*mne_ca_ca_Fin*hshare_ca_Fin_ca_f*highshare_ca_Fin_ca/w_ca_Fin_ca_f;


%India

alt_h_in_IT_in=inc_in_IT*mne_in_in_IT*highshare_in_IT_in/w_in_IT_in;
alt_h_in_Man_in=inc_in_Man*mne_in_in_Man*highshare_in_Man_in/w_in_Man_in;
alt_h_in_Oth_in=inc_in_Oth*highshare_in_Oth_in/w_in_Oth_in;
alt_h_in_Fin_in=inc_in_Fin*mne_in_in_Fin*highshare_in_Fin_in/w_in_Fin_in;

%China


alt_h_ch_IT_ch=inc_ch_IT*mne_ch_ch_IT*highshare_ch_IT_ch/w_ch_IT_ch;
alt_h_ch_Man_ch=inc_ch_Man*mne_ch_ch_Man*highshare_ch_Man_ch/w_ch_Man_ch;
alt_h_ch_Oth_ch=inc_ch_Oth*highshare_ch_Oth_ch/w_ch_Oth_ch;
alt_h_ch_Fin_ch=inc_ch_Fin*mne_ch_ch_Fin*highshare_ch_Fin_ch/w_ch_Fin_ch;

%Other

alt_h_ot_IT_ot=inc_ot_IT*highshare_ot_IT_ot/w_ot_IT_ot;
alt_h_ot_Man_ot=inc_ot_Man*highshare_ot_Man_ot/w_ot_Man_ot;
alt_h_ot_Oth_ot=inc_ot_Oth*highshare_ot_Oth_ot/w_ot_Oth_ot;
alt_h_ot_Fin_ot=inc_ot_Fin*highshare_ot_Fin_ot/w_ot_Fin_ot;



alt_L_us=l_us_IT_us*low_skill_share_us(1,1)+l_us_Man_us*low_skill_share_us(1,2)+l_us_Oth_us*low_skill_share_us(1,3)+l_us_Fin_us*low_skill_share_us(1,4);

alt_L_in=l_in_IT_in*low_skill_share_in(1,1)+l_in_Man_in*low_skill_share_in(1,2)+l_in_Oth_in*low_skill_share_in(1,3)+l_in_Fin_in*low_skill_share_in(1,4);

alt_L_eu=l_eu_IT_eu*low_skill_share_eu(1,1)+l_eu_Man_eu*low_skill_share_eu(1,2)+...
    l_eu_Oth_eu*low_skill_share_eu(1,3)+l_eu_Fin_eu*low_skill_share_eu(1,4);

alt_L_ca=l_ca_IT_ca*low_skill_share_ca(1,1)+l_ca_Man_ca*low_skill_share_ca(1,2)+l_ca_Oth_ca*low_skill_share_ca(1,3)+...
    l_ca_Fin_ca*low_skill_share_ca(1,4);

alt_L_ch=l_ch_IT_ch*low_skill_share_ch(1,1)+l_ch_Man_ch*low_skill_share_ch(1,2)+l_ch_Oth_ch*low_skill_share_ch(1,3)+l_ch_Fin_ch*low_skill_share_ch(1,4);

alt_L_ot=l_ot_IT_ot*low_skill_share_ot(1,1)+l_ot_Man_ot*low_skill_share_ot(1,2)+l_ot_Oth_ot*low_skill_share_ot(1,3)+l_ot_Fin_ot*low_skill_share_ot(1,4);



demand=[alt_h_us_IT_us_d alt_h_us_IT_us_f alt_h_us_Man_us_d alt_h_us_Man_us_f alt_h_us_Oth_us_d alt_h_us_Oth_us_f alt_h_eu_IT_eu_d alt_h_eu_IT_eu_f... 
    alt_h_eu_Man_eu_d alt_h_eu_Man_eu_f alt_h_eu_Oth_eu_d alt_h_eu_Oth_eu_f alt_h_ca_IT_ca_d alt_h_ca_IT_ca_f alt_h_ca_Man_ca_d alt_h_ca_Man_ca_f... 
    alt_h_ca_Oth_ca_d alt_h_ca_Oth_ca_f h_in_IT_in alt_h_in_Man_in alt_h_in_Oth_in alt_h_ch_IT_ch alt_h_ch_Man_ch alt_h_ch_Oth_ch alt_h_ot_IT_ot alt_h_ot_Man_ot alt_h_ot_Oth_ot...
    alt_L_us alt_L_in alt_L_eu alt_L_ca alt_L_ch alt_L_ot p_us_IT p_us_Man p_us_Oth p_in_IT p_in_Man p_in_Oth p_eu_IT p_eu_Man p_eu_Oth p_ca_IT p_ca_Man... 
    p_ca_Oth p_ch_IT p_ch_Man p_ch_Oth p_ot_IT p_ot_Man p_ot_Oth...
    alt_h_us_Fin_us_d alt_h_us_Fin_us_f...
    alt_h_eu_Fin_eu_d alt_h_eu_Fin_eu_f ...
    alt_h_ca_Fin_ca_d ...
    alt_h_ca_Fin_ca_f alt_h_in_Fin_in alt_h_ch_Fin_ch...
    alt_h_ot_Fin_ot...
    p_us_Fin p_in_Fin p_eu_Fin p_ca_Fin p_ch_Fin p_ot_Fin];

supply=[h_us_IT_us_d h_us_IT_us_f h_us_Man_us_d h_us_Man_us_f h_us_Oth_us_d h_us_Oth_us_f h_eu_IT_eu_d h_eu_IT_eu_f h_eu_Man_eu_d h_eu_Man_eu_f ...
    h_eu_Oth_eu_d h_eu_Oth_eu_f h_ca_IT_ca_d h_ca_IT_ca_f h_ca_Man_ca_d h_ca_Man_ca_f h_ca_Oth_ca_d h_ca_Oth_ca_f h_in_IT_in...
    h_in_Man_in h_in_Oth_in...
    h_ch_IT_ch h_ch_Man_ch h_ch_Oth_ch h_ot_IT_ot h_ot_Man_ot h_ot_Oth_ot ...
    L_us L_in L_eu L_ca L_ch L_ot p_us_IT_alt p_us_Man_alt p_us_Oth_alt p_in_IT_alt p_in_Man_alt p_in_Oth_alt p_eu_IT_alt p_eu_Man_alt p_eu_Oth_alt p_ca_IT_alt p_ca_Man_alt...
    p_ca_Oth_alt p_ch_IT_alt p_ch_Man_alt p_ch_Oth_alt p_ot_IT_alt p_ot_Man_alt p_ot_Oth_alt...
    h_us_Fin_us_d h_us_Fin_us_f h_eu_Fin_eu_d h_eu_Fin_eu_f ...
    h_ca_Fin_ca_d ...
    h_ca_Fin_ca_f h_in_Fin_in h_ch_Fin_ch...
    h_ot_Fin_ot...
    p_us_Fin_alt p_in_Fin_alt p_eu_Fin_alt p_ca_Fin_alt p_ch_Fin_alt p_ot_Fin_alt];




diff=demand-supply;



wage=zeros(1,139);


wage(1,1)=w_us_IT_us_d+ajust*w_us_IT_us_d*(alt_h_us_IT_us_d-h_us_IT_us_d)/(alt_h_us_IT_us_d+h_us_IT_us_d);
wage(1,2)=w_us_IT_us_f+ajust*w_us_IT_us_f*(alt_h_us_IT_us_f-h_us_IT_us_f)/(alt_h_us_IT_us_f+h_us_IT_us_f);
wage(1,3)=w_us_Man_us_d+ajust*w_us_Man_us_d*(alt_h_us_Man_us_d-h_us_Man_us_d)/(alt_h_us_Man_us_d+h_us_Man_us_d);
wage(1,4)=w_us_Man_us_f+ajust*w_us_Man_us_f*(alt_h_us_Man_us_f-h_us_Man_us_f)/(alt_h_us_Man_us_f+h_us_Man_us_f);
wage(1,5)=w_us_Oth_us_d+ajust*w_us_Oth_us_d*(alt_h_us_Oth_us_d-h_us_Oth_us_d)/(alt_h_us_Oth_us_d+h_us_Oth_us_d);
wage(1,6)=w_us_Oth_us_f+ajust*w_us_Oth_us_f*(alt_h_us_Oth_us_f-h_us_Oth_us_f)/(alt_h_us_Oth_us_f+h_us_Oth_us_f);

wage(1,31)=w_eu_IT_eu_d+ajust*w_eu_IT_eu_d*(alt_h_eu_IT_eu_d-h_eu_IT_eu_d)/(alt_h_eu_IT_eu_d+h_eu_IT_eu_d);
wage(1,32)=w_eu_IT_eu_f+ajust*w_eu_IT_eu_f*(alt_h_eu_IT_eu_f-h_eu_IT_eu_f)/(alt_h_eu_IT_eu_f+h_eu_IT_eu_f);
wage(1,33)=w_eu_Man_eu_d+ajust*w_eu_Man_eu_d*(alt_h_eu_Man_eu_d-h_eu_Man_eu_d)/(alt_h_eu_Man_eu_d+h_eu_Man_eu_d);
wage(1,34)=w_eu_Man_eu_f+ajust*w_eu_Man_eu_f*(alt_h_eu_Man_eu_f-h_eu_Man_eu_f)/(alt_h_eu_Man_eu_f+h_eu_Man_eu_f);
wage(1,35)=w_eu_Oth_eu_d+ajust*w_eu_Oth_eu_d*(alt_h_eu_Oth_eu_d-h_eu_Oth_eu_d)/(alt_h_eu_Oth_eu_d+h_eu_Oth_eu_d);
wage(1,36)=w_eu_Oth_eu_f+ajust*w_eu_Oth_eu_f*(alt_h_eu_Oth_eu_f-h_eu_Oth_eu_f)/(alt_h_eu_Oth_eu_f+h_eu_Oth_eu_f);

wage(1,61)=w_ca_IT_ca_d+ajust*w_ca_IT_ca_d*(alt_h_ca_IT_ca_d-h_ca_IT_ca_d)/(alt_h_ca_IT_ca_d+h_ca_IT_ca_d);
wage(1,62)=w_ca_IT_ca_f+ajust*w_ca_IT_ca_f*(alt_h_ca_IT_ca_f-h_ca_IT_ca_f)/(alt_h_ca_IT_ca_f+h_ca_IT_ca_f);
wage(1,63)=w_ca_Man_ca_d+ajust*w_ca_Man_ca_d*(alt_h_ca_Man_ca_d-h_ca_Man_ca_d)/(alt_h_ca_Man_ca_d+h_ca_Man_ca_d);
wage(1,64)=w_ca_Man_ca_f+ajust*w_ca_Man_ca_f*(alt_h_ca_Man_ca_f-h_ca_Man_ca_f)/(alt_h_ca_Man_ca_f+h_ca_Man_ca_f);
wage(1,65)=w_ca_Oth_ca_d+ajust*w_ca_Oth_ca_d*(alt_h_ca_Oth_ca_d-h_ca_Oth_ca_d)/(alt_h_ca_Oth_ca_d+h_ca_Oth_ca_d);
wage(1,66)=w_ca_Oth_ca_f+ajust*w_ca_Oth_ca_f*(alt_h_ca_Oth_ca_f-h_ca_Oth_ca_f)/(alt_h_ca_Oth_ca_f+h_ca_Oth_ca_f);

wage(1,92)=w_in_IT_in+ajust*w_in_IT_in*(alt_h_in_IT_in-h_in_IT_in)/(alt_h_in_IT_in+h_in_IT_in);
wage(1,97)=w_in_Man_in+ajust*w_in_Man_in*(alt_h_in_Man_in-h_in_Man_in)/(alt_h_in_Man_in+h_in_Man_in);
wage(1,101)=w_in_Oth_in+ajust*w_in_Oth_in*(alt_h_in_Oth_in-h_in_Oth_in)/(alt_h_in_Oth_in+h_in_Oth_in);

wage(1,106)=w_ch_IT_ch+ajust*w_ch_IT_ch*(alt_h_ch_IT_ch-h_ch_IT_ch)/(alt_h_ch_IT_ch+h_ch_IT_ch);
wage(1,111)=w_ch_Man_ch+ajust*w_ch_Man_ch*(alt_h_ch_Man_ch-h_ch_Man_ch)/(alt_h_ch_Man_ch+h_ch_Man_ch);
wage(1,112)=w_ch_Oth_ch+ajust*w_ch_Oth_ch*(alt_h_ch_Oth_ch-h_ch_Oth_ch)/(alt_h_ch_Oth_ch+h_ch_Oth_ch);

wage(1,113)=w_ot_IT_ot+ajust*w_ot_IT_ot*(alt_h_ot_IT_ot-h_ot_IT_ot)/(alt_h_ot_IT_ot+h_ot_IT_ot);
wage(1,114)=w_ot_Man_ot+ajust*w_ot_Man_ot*(alt_h_ot_Man_ot-h_ot_Man_ot)/(alt_h_ot_Man_ot+h_ot_Man_ot);
wage(1,115)=w_ot_Oth_ot+ajust*w_ot_Oth_ot*(alt_h_ot_Oth_ot-h_ot_Oth_ot)/(alt_h_ot_Oth_ot+h_ot_Oth_ot);

wage(1,116)=w_us_L+ajust*w_us_L*(alt_L_us-L_us)/(alt_L_us+L_us);
wage(1,117)=w_in_L+ajust*w_in_L*(alt_L_in-L_in)/(alt_L_in+L_in);
wage(1,118)=w_eu_L+ajust*w_eu_L*(alt_L_eu-L_eu)/(alt_L_eu+L_eu);
wage(1,119)=w_ca_L+ajust*w_ca_L*(alt_L_ca-L_ca)/(alt_L_ca+L_ca);
wage(1,120)=w_ch_L+ajust*w_ch_L*(alt_L_ch-L_ch)/(alt_L_ch+L_ch);
wage(1,121)=w_ot_L+ajust*w_ot_L*(alt_L_ot-L_ot)/(alt_L_ot+L_ot);

wage(1,122)=p_us_IT_alt+ajust*p_us_IT_alt*(p_us_IT-p_us_IT_alt)/(p_us_IT+p_us_IT_alt); 
wage(1,123)=p_us_Man_alt+ajust*p_us_Man_alt*(p_us_Man-p_us_Man_alt)/(p_us_Man+p_us_Man_alt); 
wage(1,124)=p_us_Oth_alt+ajust*p_us_Oth_alt*(p_us_Oth-p_us_Oth_alt)/(p_us_Oth+p_us_Oth_alt); 
wage(1,125)=p_in_IT_alt+ajust*p_in_IT_alt*(p_in_IT-p_in_IT_alt)/(p_in_IT+p_in_IT_alt); 
wage(1,126)=p_in_Man_alt+ajust*p_in_Man_alt*(p_in_Man-p_in_Man_alt)/(p_in_Man+p_in_Man_alt); 
wage(1,127)=p_in_Oth_alt+ajust*p_in_Oth_alt*(p_in_Oth-p_in_Oth_alt)/(p_in_Oth+p_in_Oth_alt); 
wage(1,128)=p_eu_IT_alt+ajust*p_eu_IT_alt*(p_eu_IT-p_eu_IT_alt)/(p_eu_IT+p_eu_IT_alt); 
wage(1,129)=p_eu_Man_alt+ajust*p_eu_Man_alt*(p_eu_Man-p_eu_Man_alt)/(p_eu_Man+p_eu_Man_alt); 
wage(1,130)=p_eu_Oth_alt+ajust*p_eu_Oth_alt*(p_eu_Oth-p_eu_Oth_alt)/(p_eu_Oth+p_eu_Oth_alt); 
wage(1,131)=p_ca_IT_alt+ajust*p_ca_IT_alt*(p_ca_IT-p_ca_IT_alt)/(p_ca_IT+p_ca_IT_alt); 
wage(1,132)=p_ca_Man_alt+ajust*p_ca_Man_alt*(p_ca_Man-p_ca_Man_alt)/(p_ca_Man+p_ca_Man_alt); 
wage(1,133)=p_ca_Oth_alt+ajust*p_ca_Oth_alt*(p_ca_Oth-p_ca_Oth_alt)/(p_ca_Oth+p_ca_Oth_alt); 
wage(1,134)=p_ch_IT_alt+ajust*p_ch_IT_alt*(p_ch_IT-p_ch_IT_alt)/(p_ch_IT+p_ch_IT_alt); 
wage(1,135)=p_ch_Man_alt+ajust*p_ch_Man_alt*(p_ch_Man-p_ch_Man_alt)/(p_ch_Man_alt+p_ch_Man_alt); 
wage(1,136)=p_ch_Oth_alt+ajust*p_ch_Oth_alt*(p_ch_Oth-p_ch_Oth_alt)/(p_ch_Oth_alt+p_ch_Oth_alt); 
wage(1,137)=p_ot_IT_alt+ajust*p_ot_IT_alt*(p_ot_IT-p_ot_IT_alt)/(p_ot_IT_alt+p_ot_IT_alt); 
wage(1,138)=p_ot_Man_alt+ajust*p_ot_Man_alt*(p_ot_Man-p_ot_Man_alt)/(p_ot_Man_alt+p_ot_Man_alt); 
wage(1,139)=p_ot_Oth_alt+ajust*p_ot_Oth_alt*(p_ot_Oth-p_ot_Oth_alt)/(p_ot_Oth_alt+p_ot_Oth_alt);


wage(1,140)=w_us_Fin_us_d+ajust*w_us_Fin_us_d*(alt_h_us_Fin_us_d-h_us_Fin_us_d)/(alt_h_us_Fin_us_d+h_us_Fin_us_d);
wage(1,141)=w_us_Fin_us_f+ajust*w_us_Fin_us_f*(alt_h_us_Fin_us_f-h_us_Fin_us_f)/(alt_h_us_Fin_us_f+h_us_Fin_us_f);

wage(1,154)=w_eu_Fin_eu_d+ajust*w_eu_Fin_eu_d*(alt_h_eu_Fin_eu_d-h_eu_Fin_eu_d)/(alt_h_eu_Fin_eu_d+h_eu_Fin_eu_d);
wage(1,155)=w_eu_Fin_eu_f+ajust*w_eu_Fin_eu_f*(alt_h_eu_Fin_eu_f-h_eu_Fin_eu_f)/(alt_h_eu_Fin_eu_f+h_eu_Fin_eu_f);

wage(1,168)=w_ca_Fin_ca_d+ajust*w_ca_Fin_ca_d*(alt_h_ca_Fin_ca_d-h_ca_Fin_ca_d)/(alt_h_ca_Fin_ca_d+h_ca_Fin_ca_d);
wage(1,169)=w_ca_Fin_ca_f+ajust*w_ca_Fin_ca_f*(alt_h_ca_Fin_ca_f-h_ca_Fin_ca_f)/(alt_h_ca_Fin_ca_f+h_ca_Fin_ca_f);

wage(1,183)=w_in_Fin_in+ajust*w_in_Fin_in*(alt_h_in_Fin_in-h_in_Fin_in)/(alt_h_in_Fin_in+h_in_Fin_in);

wage(1,191)=w_ch_Fin_ch+ajust*w_ch_Fin_ch*(alt_h_ch_Fin_ch-h_ch_Fin_ch)/(alt_h_ch_Fin_ch+h_ch_Fin_ch);
wage(1,192)=w_ot_Fin_ot+ajust*w_ot_Fin_ot*(alt_h_ot_Fin_ot-h_ot_Fin_ot)/(alt_h_ot_Fin_ot+h_ot_Fin_ot);
wage(1,193)=p_us_Fin_alt+ajust*p_us_Fin_alt*(p_us_Fin-p_us_Fin_alt)/(p_us_Fin+p_us_Fin_alt); 
wage(1,194)=p_in_Fin_alt+ajust*p_in_Fin_alt*(p_in_Fin-p_in_Fin_alt)/(p_in_Fin+p_in_Fin_alt); 
wage(1,195)=p_eu_Fin_alt+ajust*p_eu_Fin_alt*(p_eu_Fin-p_eu_Fin_alt)/(p_eu_Fin+p_eu_Fin_alt); 
wage(1,196)=p_ca_Fin_alt+ajust*p_ca_Fin_alt*(p_ca_Fin-p_ca_Fin_alt)/(p_ca_Fin+p_ca_Fin_alt); 
wage(1,197)=p_ch_Fin_alt+ajust*p_ch_Fin_alt*(p_ch_Fin-p_ch_Fin_alt)/(p_ch_Fin_alt+p_ch_Fin_alt); 
wage(1,198)=p_ot_Fin_alt+ajust*p_ot_Fin_alt*(p_ot_Fin-p_ot_Fin_alt)/(p_ot_Fin_alt+p_ot_Fin_alt); 



omega_crit=sum(abs(diff));


end

%Variables for export:

Revenues=[inc_ca_IT inc_ca_Man inc_ca_Oth inc_ch_IT inc_ch_Man inc_ch_Oth inc_eu_IT inc_eu_Man inc_eu_Oth inc_in_IT inc_in_Man inc_in_Oth inc_ot_IT inc_ot_Man inc_ot_Oth inc_us_IT inc_us_Man inc_us_Oth]';
Revenues_Fin=[inc_us_Fin inc_in_Fin inc_eu_Fin inc_ca_Fin inc_ch_Fin inc_eu_Fin]';

US_Rev_source=[mne_us_us_IT*inc_us_IT mne_us_us_Man*inc_us_Man 1 1 1 1 1 1 1 1]';
US_Rev_source_Fin=[mne_us_us_Fin*inc_us_Fin 1 1 1 1]';

mne_shares=[mne_us_us_IT mne_us_us_Man 1 1 1 1 1 1 1 1]';
mne_shares_Fin=[mne_us_us_Fin 1 1 1 1]';



revenues_alt_us_IT=mne_us_us_IT*inc_us_IT*MNE_shares_IT_us(1,1);
revenues_alt_us_Man=mne_us_us_Man*inc_us_Man*MNE_shares_Man_us(1,1);
revenues_alt_us_Fin=mne_us_us_Fin*inc_us_Fin*MNE_shares_Fin_us(1,1);


%Production shares by country

revenue_shares=[1.28E-01	8.80E-02	7.16E-01	6.85E-02...
4.05E-02	1.07E-01	8.19E-01	3.33E-02...
8.75E-02	5.98E-02	7.96E-01	5.63E-02...
4.40E-02	2.33E-01	6.97E-01	2.64E-02...
1.05E-01	1.10E-01	7.28E-01	5.63E-02...
6.32E-02	1.23E-01	7.76E-01	3.81E-02];

total_us_output=inc_us_IT*revenue_shares(1,1)+inc_us_Man*revenue_shares(1,2)+inc_us_Oth*revenue_shares(1,3)+inc_us_Fin*revenue_shares(1,4);
total_in_output=inc_in_IT*revenue_shares(1,5)+inc_in_Man*revenue_shares(1,6)+inc_in_Oth*revenue_shares(1,7)+inc_in_Fin*revenue_shares(1,8);
total_ca_output=inc_ca_IT*revenue_shares(1,9)+inc_ca_Man*revenue_shares(1,10)+inc_ca_Oth*revenue_shares(1,11)+inc_ca_Fin*revenue_shares(1,12);
total_ch_output=inc_ch_IT*revenue_shares(1,13)+inc_ch_Man*revenue_shares(1,14)+inc_ch_Oth*revenue_shares(1,15)+inc_ch_Fin*revenue_shares(1,16);
total_eu_output=inc_eu_IT*revenue_shares(1,17)+inc_eu_Man*revenue_shares(1,18)+inc_eu_Oth*revenue_shares(1,19)+inc_eu_Fin*revenue_shares(1,20);
total_ot_output=inc_ot_IT*revenue_shares(1,21)+inc_ot_Man*revenue_shares(1,22)+inc_ot_Oth*revenue_shares(1,23)+inc_ot_Fin*revenue_shares(1,24);

total_output=[total_us_output total_in_output total_eu_output total_ca_output total_ch_output total_ot_output]';

Trade_shares_us_importer=[trade_us_us_IT trade_us_us_Man trade_us_us_Oth trade_us_in_IT trade_us_in_Man trade_us_in_Oth trade_us_eu_IT trade_us_eu_Man trade_us_eu_Oth trade_us_ca_IT trade_us_ca_Man trade_us_ca_Oth trade_us_ch_IT trade_us_ch_Man trade_us_ch_Oth  trade_us_ot_IT trade_us_ot_Man trade_us_ot_Oth]';
Trade_shares_us_importer_Fin=[trade_us_us_Fin trade_us_in_Fin trade_us_eu_Fin trade_us_ca_Fin trade_us_ch_Fin trade_us_ot_Fin]';

domestic_trade=[1.29E-01	7.07E-02	7.31E-01	6.92E-02];

domestic_trade_share_us=trade_us_us_IT*domestic_trade(1,1)+trade_us_us_Man*domestic_trade(1,2)+trade_us_us_Oth*domestic_trade(1,3)+trade_us_us_Fin*domestic_trade(1,4);



%High skill employment Natives

share_emp_man_us=[0.760839365	0.000175563	0.226123575	0.012820179	4.13186E-05];
share_emp_it_us=[0.970225499	0.00019793	0.027741165	0.001804571	3.08349E-05];
share_emp_fin_us=[8.80E-01	8.86E-05	9.55E-02	2.48E-02	5.13E-05];

native_emp_IT_tot=mig_us_IT_us_us;
native_emp_Man_tot=mig_us_Man_us_us;
native_emp_Fin_tot=mig_us_Fin_us_us;

Native_employment=[mig_us_IT_us_us 1 1 1 1 mig_us_Man_us_us 1 1 1 1]';
Native_employment_Fin=[mig_us_Fin_us_us 1 1 1 1]';

%Low skill employment

emp_it_us_low=l_us_IT_us;
emp_man_us_low=l_us_Man_us;
emp_fin_us_low=l_us_Fin_us;



%Welfare

shares_domestic_income=[total_shares_us_us(1,1) total_shares_us_us(1,4) total_shares_us_us(1,7) total_shares_us_us(1,10)]'/sum([total_shares_us_us(1,1)...
    total_shares_us_us(1,4) total_shares_us_us(1,7) total_shares_us_us(1,10)]);


price_index_us=[p_us_IT p_us_Man p_us_Oth p_us_Fin]';

income=[h_us_IT_us_d*w_us_IT_us_d h_us_Man_us_d*w_us_Man_us_d h_us_Oth_us_d*w_us_Oth_us_d h_us_Fin_us_d*w_us_Fin_us_d]';


%Change in domestic workers
domestic_workers=(mig_us_IT_us_us*mig_us(1,1)+...
    mig_us_Man_us_us*mig_us(1,2)+...    
    mig_us_Oth_us_us*mig_us(1,3)+mig_us_Fin_us_us*mig_us(1,10))/(mig_us(1,1)+...
    mig_us(1,2)+mig_us(1,3)+mig_us(1,10));

welfare_us=(sum((income.*shares_domestic_income))/domestic_workers)/(price_index_us(1,1)^gamma(1,1)*price_index_us(2,1)^gamma(1,2)*price_index_us(3,1)^gamma(1,3)*price_index_us(4,1)^gamma(1,4));
welfare_low=w_us_L/(price_index_us(1,1)^gamma(1,1)*price_index_us(2,1)^gamma(1,2)*price_index_us(3,1)^gamma(1,3)*price_index_us(4,1)^gamma(1,4));
total_welfare=welfare_us*0.304+welfare_low*0.696;

wage_high_us=(sum((income.*shares_domestic_income))/domestic_workers);
total_wage_us=wage_high_us*0.304+w_us_L*0.696;

income_mig_us=[h_us_IT_us_f*w_us_IT_us_f h_us_Man_us_f*w_us_Man_us_f h_us_Oth_us_f*w_us_Oth_us_f h_us_Fin_us_f*w_us_Fin_us_f];

shares_migrant_income=[total_shares_us_us(1,2) total_shares_us_us(1,5) total_shares_us_us(1,8) total_shares_us_us(1,11)]/sum([total_shares_us_us(1,2) total_shares_us_us(1,5) total_shares_us_us(1,8)... 
    total_shares_us_us(1,11)]);





%Welfare Europe

shares_domestic_income_eu=[total_shares_eu_eu(1,1) total_shares_eu_eu(1,4) total_shares_eu_eu(1,7) total_shares_eu_eu(1,10)]'/sum([total_shares_eu_eu(1,1)...
    total_shares_eu_eu(1,4) total_shares_eu_eu(1,7) total_shares_eu_eu(1,10)]);


price_index_eu=[p_eu_IT p_eu_Man p_eu_Oth p_eu_Fin]';

income_eu=[h_eu_IT_eu_d*w_eu_IT_eu_d h_eu_Man_eu_d*w_eu_Man_eu_d h_eu_Oth_eu_d*w_eu_Oth_eu_d h_eu_Fin_eu_d*w_eu_Fin_eu_d]';

%Change in domestic workers
domestic_workers_eu=(mig_eu_IT_eu_eu*mig_eu(1,4)+mig_eu_Man_eu_eu*mig_eu(1,5)+mig_eu_Oth_eu_eu*mig_eu(1,6)+mig_eu_Fin_eu_eu*mig_eu(1,11))/(mig_eu(1,4)+mig_eu(1,5)+mig_eu(1,6)+mig_eu(1,11));

welfare_eu=(sum((income_eu.*shares_domestic_income_eu))/domestic_workers_eu)/(price_index_eu(1,1)^gamma_eu(1,1)*price_index_eu(2,1)^gamma_eu(1,2)*price_index_eu(3,1)^gamma_eu(1,3)*price_index_eu(4,1)^gamma_eu(1,4));
welfare_low_eu=w_eu_L/(price_index_eu(1,1)^gamma_eu(1,1)*price_index_eu(2,1)^gamma_eu(1,2)*price_index_eu(3,1)^gamma_eu(1,3)*price_index_eu(4,1)^gamma_eu(1,4));
total_welfare_eu=welfare_eu*0.27+welfare_low_eu*0.73;

%Welfare Canada

shares_domestic_income_ca=[total_shares_ca_ca(1,1) total_shares_ca_ca(1,4) total_shares_ca_ca(1,7) total_shares_ca_ca(1,10)]'/sum([total_shares_ca_ca(1,1) total_shares_ca_ca(1,4),...
    total_shares_ca_ca(1,7) total_shares_ca_ca(1,10)]);

income_ca=[h_ca_IT_ca_d*w_ca_IT_ca_d h_ca_Man_ca_d*w_ca_Man_ca_d h_ca_Oth_ca_d*w_ca_Oth_ca_d h_ca_Fin_ca_d*w_ca_Fin_ca_d]';

price_index_ca=[p_ca_IT p_ca_Man p_ca_Oth p_ca_Fin]';


%Change in domestic workers
domestic_workers_ca=(mig_ca_IT_ca_ca*mig_ca(1,7)+mig_ca_Man_ca_ca*mig_ca(1,8)+...    
    mig_ca_Oth_ca_ca*mig_ca(1,9)+mig_ca_Fin_ca_ca*mig_ca(1,12))/(mig_ca(1,7)+mig_ca(1,8)+mig_ca(1,9)+mig_ca(1,12));

welfare_ca=(sum((income_ca.*shares_domestic_income_ca))/domestic_workers_ca)/(price_index_ca(1,1)^gamma_ca(1,1)*price_index_ca(2,1)^gamma_ca(1,2)*price_index_ca(3,1)^gamma_ca(1,3)*price_index_ca(4,1)^gamma_ca(1,4));
welfare_low_ca=w_ca_L/(price_index_ca(1,1)^gamma_ca(1,1)*price_index_ca(2,1)^gamma_ca(1,2)*price_index_ca(3,1)^gamma_ca(1,3)*price_index_ca(4,1)^gamma_ca(1,4));
total_welfare_ca=welfare_ca*0.23+welfare_low_ca*0.77;

%Welfare India

shares_domestic_income_in=[total_shares_in_in(1,1) total_shares_in_in(1,2) total_shares_in_in(1,3) total_shares_in_in(1,7)]'/sum([total_shares_in_in(1,1)...
    total_shares_in_in(1,2) total_shares_in_in(1,3) total_shares_in_in(1,7)]);

income_in=[h_in_IT_in*w_in_IT_in h_in_Man_in*w_in_Man_in h_in_Oth_in*w_in_Oth_in h_in_Fin_in*w_in_Fin_in]';



price_index_in=[p_in_IT p_in_Man p_in_Oth p_in_Fin]';

%Change in domestic workers
domestic_workers_in=(mig_in_IT_in_in*mig_in(1,10)+mig_in_Man_in_in*mig_in(1,11)+mig_in_Oth_in_in*mig_in(1,12)+mig_in_Fin_in_in*mig_in(1,16))/(mig_in(1,10)+mig_in(1,11)+mig_in(1,12)+mig_in(1,16));

welfare_in=(sum((income_in.*shares_domestic_income_in))/domestic_workers_in)/(price_index_in(1,1)^gamma_in(1,1)*price_index_in(2,1)^gamma_in(1,2)*price_index_in(3,1)^gamma_in(1,3)*price_index_in(4,1)^gamma_in(1,4));
welfare_low_in=w_in_L/(price_index_in(1,1)^gamma_in(1,1)*price_index_in(2,1)^gamma_in(1,2)*price_index_in(3,1)^gamma_in(1,3)*price_index_in(4,1)^gamma_in(1,4));
total_welfare_in=welfare_in*0.08+welfare_low_in*0.92;


%Welfare China

shares_domestic_income_ch=[total_shares_ch_ch(1,1) total_shares_ch_ch(1,2) total_shares_ch_ch(1,3) total_shares_ch_ch(1,7)]'/sum([total_shares_ch_ch(1,1)...
    total_shares_ch_ch(1,2) total_shares_ch_ch(1,3) total_shares_ch_ch(1,7)]);

income_ch=[h_ch_IT_ch*w_ch_IT_ch h_ch_Man_ch*w_ch_Man_ch h_ch_Oth_ch*w_ch_Oth_ch h_ch_Fin_ch*w_ch_Fin_ch]';


price_index_ch=[p_ch_IT p_ch_Man p_ch_Oth p_ch_Fin]';

%Change in domestic workers
domestic_workers_ch=(mig_ch_IT_ch_ch*mig_ch(1,10)+...
    mig_ch_Man_ch_ch*mig_ch(1,11)+...    
    mig_ch_Oth_ch_ch*mig_ch(1,12)+...
    mig_ch_Fin_ch_ch*mig_ch(1,16))/(mig_ch(1,10)+mig_ch(1,11)+mig_ch(1,12)+mig_ch(1,16));

welfare_ch=(sum((income_ch.*shares_domestic_income_ch))/domestic_workers_ch)/(price_index_ch(1,1)^gamma_ch(1,1)*price_index_ch(2,1)^gamma_ch(1,2)*price_index_ch(3,1)^gamma_ch(1,3)*price_index_ch(4,1)^gamma_ch(1,4));
welfare_low_ch=w_ch_L/(price_index_ch(1,1)^gamma_ch(1,1)*price_index_ch(2,1)^gamma_ch(1,2)*price_index_ch(3,1)^gamma_ch(1,3)*price_index_ch(4,1)^gamma_ch(1,4));
total_welfare_ch=welfare_ch*0.08+welfare_low_ch*0.92;


%Welfare Other

shares_domestic_income_ot=[total_shares_ot(1,1) total_shares_ot(1,2) total_shares_ot(1,3)  total_shares_ot(1,4)]'/sum([total_shares_ot(1,1) total_shares_ot(1,2) total_shares_ot(1,3)  total_shares_ot(1,4)]);

income_ot=[h_ot_IT_ot*w_ot_IT_ot h_ot_Man_ot*w_ot_Man_ot h_ot_Oth_ot*w_ot_Oth_ot h_ot_Fin_ot*w_ot_Fin_ot]';


price_index_ot=[p_ot_IT p_ot_Man p_ot_Oth p_ot_Fin]';

%Change in domestic workers
domestic_workers_ot=(mig_ot_IT_ot_ot*mig_ot(1,10)+mig_ot_Man_ot_ot*mig_ot(1,11)+mig_ot_Oth_ot_ot*mig_ot(1,12)+mig_ot_Fin_ot_ot*mig_ot(1,16))/(mig_ot(1,10)+mig_ot(1,11)+mig_ot(1,12)+mig_ot(1,16));

welfare_ot=(sum((income_ot.*shares_domestic_income_ot))/domestic_workers_ot)/(price_index_ot(1,1)^gamma_ot(1,1)*price_index_ot(2,1)^gamma_ot(1,2)*price_index_ot(3,1)^gamma_ot(1,3)*price_index_ot(4,1)^gamma_ot(1,4));
welfare_low_ot=w_ot_L/(price_index_ot(1,1)^gamma_ot(1,1)*price_index_ot(2,1)^gamma_ot(1,2)*price_index_ot(3,1)^gamma_ot(1,3)*price_index_ot(4,1)^gamma_ot(1,4));
total_welfare_ot=welfare_ot*0.08+welfare_low_ot*0.92;


%Total welfare

welfare_aggregate=[welfare_us welfare_low total_welfare...
    welfare_eu welfare_low_eu total_welfare_eu...
    welfare_ca welfare_low_ca total_welfare_ca...
    welfare_in welfare_low_in total_welfare_in...
    welfare_ch welfare_low_ch total_welfare_ch...
    welfare_ot welfare_low_ot total_welfare_ot]';


%Total migration
migration_abroad=[mig_ca_Man_us_us mig_in_Man_us_us mig_ch_Man_us_us mig_eu_Man_us_us mig_ot_Man_us_us...
    mig_ca_IT_us_us mig_in_IT_us_us mig_ch_IT_us_us mig_eu_IT_us_us mig_ot_IT_us_us...
    mig_ca_Oth_us_us mig_in_Oth_us_us mig_ch_Oth_us_us mig_eu_Oth_us_us mig_ot_Oth_us_us...
    mig_ca_Fin_us_us mig_in_Fin_us_us mig_ch_Fin_us_us mig_eu_Fin_us_us mig_ot_Fin_us_us];

migration_shares=[sum([0.002625866	0.033253354	0.007232554	0.00223212	0.007865503])...
sum([0.000206008	0.000327872	8.41442E-05	0.000110258	0.000252433])...
sum([9.9712E-06	0.000599768	7.77754E-05	4.48704E-06	3.39021E-05])...
sum([5.66653E-06	0.000188255	2.51846E-06	3.14807E-06	8.18499E-06])...
sum([0.001125963	0.010016216	0.001830647	0.001008515	0.003316611])...
sum([0.003487783	0.12617343	0.008751747	0.003721947	0.014875713])...
sum([1.59446E-05	0.000236606	1.76529E-05	1.12466E-05	3.14621E-05])...
sum([5.89517E-08	4.90478E-06	2.65283E-06	2.00436E-07	1.02576E-06])...
sum([7.1191E-05	0.00364932	4.10384E-05	5.8605E-05	0.00010707])...
sum([0.000572612	0.020811345	0.000981303	0.000758786	0.002409867])...
0.041573757	0.377195911	0.067241175	0.039952316	0.1535505...
sum([0.001475668	0.019448042	0.004958523	0.001514832	0.004891384])...
sum([0.000253959	0.000645782	0.000330147	0.000119724	0.000341031])...
sum([9.52106E-06	9.28303E-05	0.00027373	3.5704E-05	8.0929E-05])...
sum([5.32537E-06	7.45429E-05	5.32537E-06	6.39044E-05	4.26029E-05])...
sum([0.001243482	0.012346701	0.00351504	0.0032262	0.006276158])];



mig_change=sum(migration_abroad.*migration_shares);


%Migration by origin country

mig_shares_ca=[migration_shares(1,1) migration_shares(1,6) migration_shares(1,11) migration_shares(1,16)]/sum([migration_shares(1,1) migration_shares(1,6) migration_shares(1,11) migration_shares(1,16)]);

mig_shares_in=[migration_shares(1,2) migration_shares(1,7) migration_shares(1,12) migration_shares(1,17)]/sum([migration_shares(1,2) migration_shares(1,7) migration_shares(1,12) migration_shares(1,17)]);

mig_shares_ch=[migration_shares(1,3) migration_shares(1,8) migration_shares(1,13) migration_shares(1,18)]/sum([migration_shares(1,3) migration_shares(1,8) migration_shares(1,13) migration_shares(1,18)]);

mig_shares_eu=[migration_shares(1,4) migration_shares(1,9) migration_shares(1,14) migration_shares(1,19)]/sum([migration_shares(1,4) migration_shares(1,9) migration_shares(1,14) migration_shares(1,19)]);

mig_shares_ot=[migration_shares(1,5) migration_shares(1,10) migration_shares(1,15) migration_shares(1,20)]/sum([migration_shares(1,5) migration_shares(1,10) migration_shares(1,15) migration_shares(1,20)]);


mig_us_ca=mig_ca_Man_us_us*mig_shares_ca(1,1)+mig_ca_IT_us_us*mig_shares_ca(1,2)+mig_ca_Oth_us_us*mig_shares_ca(1,3)+mig_ca_Fin_us_us*mig_shares_ca(1,4);

mig_us_in=mig_in_Man_us_us*mig_shares_in(1,1)+mig_in_IT_us_us*mig_shares_in(1,2)+mig_in_Oth_us_us*mig_shares_in(1,3)+mig_in_Fin_us_us*mig_shares_in(1,4);

mig_us_ch=mig_ch_Man_us_us*mig_shares_ch(1,1)+mig_ch_IT_us_us*mig_shares_ch(1,2)+mig_ch_Oth_us_us*mig_shares_ch(1,3)+mig_ch_Fin_us_us*mig_shares_ch(1,4);

mig_us_eu=mig_eu_Man_us_us*mig_shares_eu(1,1)+mig_eu_IT_us_us*mig_shares_eu(1,2)+mig_eu_Oth_us_us*mig_shares_eu(1,3)+mig_eu_Fin_us_us*mig_shares_eu(1,4);

mig_us_ot=mig_ot_Man_us_us*mig_shares_ot(1,1)+mig_ot_IT_us_us*mig_shares_ot(1,2)+mig_ot_Oth_us_us*mig_shares_ot(1,3)+mig_ot_Fin_us_us*mig_shares_ot(1,4);




%Migration to canada


migration_abroad_ca=[mig_us_IT_ca_ca...
mig_us_Man_ca_ca...
mig_us_Oth_ca_ca...
mig_eu_IT_ca_ca...
mig_eu_Man_ca_ca...
mig_eu_Oth_ca_ca...
mig_in_IT_ca_ca...
mig_in_Man_ca_ca...
mig_in_Oth_ca_ca...
mig_ch_IT_ca_ca...
mig_ch_Man_ca_ca... 
mig_ch_Oth_ca_ca...
mig_ot_IT_ca_ca...
mig_ot_Man_ca_ca...
mig_ot_Oth_ca_ca...
mig_us_Fin_ca_ca...
mig_eu_Fin_ca_ca...
mig_in_Fin_ca_ca...
mig_ch_Fin_ca_ca...
mig_ot_Fin_ca_ca];



migration_shares_ca=[sum([0.002094265	1.27745E-07	2.16925E-05	0.007985385	1.25234E-05])...	
sum([0.005582421	1.19536E-07	8.68855E-06	0.000495105	3.47734E-06])...	
0.034265421...
sum([0.002976497	4.47278E-07	0.000100705	0.027959427	4.38485E-05])...	
sum([0.006116451	6.02329E-07	6.40144E-05	0.002494784	1.7522E-05])...	
0.10272754...
sum([0.00157609	2.78367E-07	4.02176E-05	0.014804841	2.32183E-05])...	
sum([0.006767692	1.03234E-06	4.84422E-05	0.002760413	1.93876E-05])...	
0.071570015...
sum([0.001950516	2.93104E-07	4.9772E-05	0.018321976	0.000363685])...	
sum([0.006077421	5.98486E-07	4.35013E-05	0.002478864	1.33668E-05])...	
0.056689046...
sum([0.009468501	1.42283E-06	0.000241611	0.088941407	0.000139486])...	
sum([0.034132428	3.36126E-06	0.000244315	0.013921967	9.77801E-05])...	
0.430372212...
sum([0.0007107	4.71677E-08	1.59452E-06	0.00119484	4.67643E-09])...						
sum([0.000783107	1.84217E-07	2.05489E-05	0.004666546	1.82642E-08])...						
sum([0.000754543	1.09512E-07	6.00039E-06	0.004496333	1.7598E-08])...						
sum([0.000820167	1.92935E-07	6.52226E-06	0.004887387	1.11161E-07])...						
sum([0.003949178	9.29E-07	3.14052E-05	0.023533198	9.21055E-08])];

mig_change_ca=sum(migration_abroad_ca.*migration_shares_ca);

%Migration to Europe

migration_abroad_eu=[mig_us_IT_eu_eu...
mig_us_Man_eu_eu...
mig_us_Oth_eu_eu...
mig_ca_IT_eu_eu...
mig_ca_Man_eu_eu...
mig_ca_Oth_eu_eu...
mig_in_IT_eu_eu...
mig_in_Man_eu_eu...
mig_in_Oth_eu_eu...
mig_ch_IT_eu_eu...
mig_ch_Man_eu_eu...
mig_ch_Oth_eu_eu...
mig_ot_IT_eu_eu...
mig_ot_Man_eu_eu...
mig_ot_Oth_eu_eu...
mig_us_Fin_eu_eu...
mig_ca_Fin_eu_eu...
mig_in_Fin_eu_eu...
mig_ch_Fin_eu_eu...
mig_ot_Fin_eu_eu];


migration_shares_eu=[sum([0.000932423	1.93762E-05	0.008889599	3.65276E-05	1.9529E-05])...	
sum([0.000546424	1.96882E-05	0.001478215	8.65161E-06	3.80074E-05])...	
0.039125427...
sum([0.000433467	1.15151E-05	0.00528299	2.17079E-05	7.73948E-05])...	
sum([0.00016728	8.58274E-06	0.000644402	3.77152E-06	1.29888E-05])...	
0.028886509...
sum([0.000256993	6.82701E-06	0.003132166	3.05355E-05	6.88087E-06])...	
sum([0.000188933	9.69366E-06	0.000727811	2.005E-05	1.87133E-05])...	
0.009788118...
sum([0.000389438	1.2037E-05	0.004746373	1.9503E-05	1.0427E-05])...	
sum([0.000261354	1.98073E-05	0.001006793	5.8925E-06	2.58863E-05])...	
0.044928231...
sum([0.008470829	0.000225027	0.103240315	0.000424217	0.000226803])...	
sum([0.005618019	0.000288247	0.021641879	0.000126664	0.000556449])...	
0.663214993...
sum([0.000916614	2.67468E-05	0.002619044	2.71482E-05	7.47573E-05])...						
sum([0.000157011	1.34784E-05	0.001319801	1.36807E-05	0.000150996])...						
sum([9.20938E-05	7.90568E-06	0.000774122	2.77382E-05	2.20963E-05])...						
sum([0.000165714	9.05834E-06	0.001392961	1.4439E-05	3.97603E-05])...						
sum([0.003648588	0.000313209	0.030669329	0.000317909	0.000875417])];

mig_change_eu=sum(migration_abroad_eu.*migration_shares_eu);


%variables=[Revenues;US_Rev_source;Trade_shares_us_exporter;Trade_shares_us_importer;Native_employment;average_wage_IT;average_wage_Man;average_wage_IT_total;average_wage_Man_total;total_change_IT;total_change_Man;trade_us_us_IT;trade_us_us_Man;trade_ca_us_Oth;price_index_us; income; migration_abroad' ;welfare_us;welfare_low;total_welfare];

%Employment MNEs

%IT Man				
%low skill	domestic	source	foreign

employment_shares_us=[0.390536756	0.549405325	0	0.060057919	0.452899804	0.511643957	0	0.035456238	0.502851732	0.471628684	0	0.025519585];
employment_shares_in=[0.390536756	0.068941975	0.502272076	0.038249193	0.452899804	0.369819004	0.160627504	0.016653688	0.502851732	0.13987408	0.138926068	0.21834812];
employment_shares_eu=[0.390536756	0.37968163	0.006828369	0.222953245	0.452899804	0.508854244	0.002229838	0.036016113	0.502851732	0.355273375	0.017202494	0.124672399];
employment_shares_ca=[0.390536756	0.545585231	0.003254931	0.060623082	0.452899804	0.508854244	0.008033913	0.030212038	0.502851732	0.451823253	0.006808479	0.038516537];
employment_shares_ch=[0.390536756	0.510931527	0.029559515	0.068972201	0.452899804	0.315573108	0.024806474	0.206720614	0.502851732	0.064658461	0.240272115	0.192217692];
				

employment_us_IT_us=(l_us_IT_us*employment_shares_us(1,1)+mig_us_IT_us_us*employment_shares_us(1,2)+employment_shares_us(1,4)*(mig_in_IT_us_us*Foreign_IT_us_us(1,1)+...
    mig_eu_IT_us_us*Foreign_IT_us_us(1,2)+mig_ca_IT_us_us*Foreign_IT_us_us(1,3)+mig_ch_IT_us_us*Foreign_IT_us_us(1,4)+mig_ot_IT_us_us*Foreign_IT_us_us(1,5)))/sum([employment_shares_us(1,1) employment_shares_us(1,2) employment_shares_us(1,4)]);

employment_us_Man_us=(l_us_Man_us*employment_shares_us(1,5)+mig_us_Man_us_us*employment_shares_us(1,6)+employment_shares_us(1,8)*(mig_in_Man_us_us*Foreign_Man_us_us(1,1)+...
    mig_eu_Man_us_us*Foreign_Man_us_us(1,2)+mig_ca_Man_us_us* Foreign_Man_us_us(1,3)+mig_ch_Man_us_us*Foreign_Man_us_us(1,4)+mig_ot_Man_us_us*Foreign_Man_us_us(1,5)))/sum([employment_shares_us(1,5) employment_shares_us(1,6) employment_shares_us(1,8)]);

employment_us_IT_in=1;
employment_us_Man_in=1;
employment_us_IT_eu=1;
employment_us_Man_eu=1;
employment_us_IT_ca=1;
employment_us_Man_ca=1;
employment_us_IT_ch=1;
employment_us_Man_ch=1;



employment_us_Fin_us=(l_us_Fin_us*employment_shares_us(1,9)+mig_us_Fin_us_us*employment_shares_us(1,10)+employment_shares_us(1,12)*(mig_in_Fin_us_us*Foreign_Fin_us_us(1,1)+...
    mig_eu_Fin_us_us*Foreign_Fin_us_us(1,2)+mig_ca_Fin_us_us* Foreign_Fin_us_us(1,3)+mig_ch_Fin_us_us*Foreign_Fin_us_us(1,4)+mig_ot_Fin_us_us*Foreign_Fin_us_us(1,5)))/sum([employment_shares_us(1,9) employment_shares_us(1,10) employment_shares_us(1,12)]);
employment_us_Fin_in=1;
employment_us_Fin_eu=1;
employment_us_Fin_ca=1;
employment_us_Fin_ch=1;

% (mig_us_IT_us_us*mig_us(1,1)+mig_us_IT_us_in*mig_us(1,2)+mig_us_IT_us_eu*mig_us(1,3)+mig_us_IT_us_ca*mig_us(1,4)+mig_us_IT_us_ch*mig_us(1,5)+...
%     mig_us_Man_us_us*mig_us(1,6)+mig_us_Man_us_in*mig_us(1,7)+mig_us_Man_us_eu*mig_us(1,8)+mig_us_Man_us_ca*mig_us(1,9)+mig_us_Man_us_ch*mig_us(1,10)+...    
%     mig_us_Oth_us_us*mig_us(1,11))











variables=[native_emp_IT_tot; native_emp_Man_tot; emp_it_us_low; emp_man_us_low; welfare_aggregate; Revenues; total_output; Trade_shares_us_importer;...
    domestic_trade_share_us; mig_change; mig_change_ca; mig_change_eu; mig_us_ca; mig_us_in; mig_us_ch; mig_us_eu; mig_us_ot; US_Rev_source; mne_shares;...
    wage_high_us; w_us_L; total_wage_us; employment_us_IT_us; employment_us_Man_us; employment_us_IT_in; employment_us_Man_in; employment_us_IT_eu; employment_us_Man_eu;...
    employment_us_IT_ca; employment_us_Man_ca; employment_us_IT_ch; employment_us_Man_ch;...
    native_emp_Fin_tot; emp_fin_us_low; Revenues_Fin; Trade_shares_us_importer_Fin; US_Rev_source_Fin; mne_shares_Fin; employment_us_Fin_us; employment_us_Fin_in; employment_us_Fin_eu;...
    employment_us_Fin_ca; employment_us_Fin_ch];


wage_mig_us=sum(income_mig_us.*shares_migrant_income)/mig_change;

%observed changes
wage_fh=wage_mig_us/wage_high_us;
wage_hl=(wage_mig_us*(1-9.02E-01)+wage_high_us*9.02E-01)/w_us_L;

emp_hl=mig_change*(1-9.02E-01)+domestic_workers*9.02E-01;
emp_fh=mig_change/domestic_workers;

ratio1=h_us_Oth_us_f/h_us_Oth_us_d;
ratio2=w_us_Oth_us_f/w_us_Oth_us_d;






omega_crit2=abs(mig_change-target_mig);

mig_cost_alt=mig_cost_change+adjust2*mig_cost_change*(mig_change-target_mig)/(mig_change+target_mig);
mig_cost_change=mig_cost_alt;



end


%Table 3: Change in real wages and compensating variation - Column "No MNE(% change)"
([welfare_us welfare_low total_welfare]-1)*100

toc